Modify unique constraint in Oracle - sql

I need to update an existing constraint in Oracle database to add a new column there.
ALTER TABLE MY_PARTNER_DETAILS
MODIFY CONSTRAINT UQ_MY_PARTNER_DETAILS
UNIQUE(PARTNER_CODE,PGOOD_CODE,SITE_CODE,PARTNER_PLACEMENT,PARTNER_PARTICIPATION)
Gives the error:
Error at line 1
ORA-00933: SQL command not properly ended
What's the problem with that?

You should drop and recreate the constraint. modify constraint allows you to change constraint's state not definition.
See: Oracle Docs

Related

Oracle SQL statement error - ORA-00905: missing keyword

Can someone please help me with the following Oracle SQL Statement. I am getting an error:
ORA-00905: missing keyword
ALTER TABLE loan_transaction_codes
ADD FOREIGN KEY (non_accrual_debit_code)
REFERENCES dbo.general_ledger_accounts (gl_account_no)
ON UPDATE NO ACTION
ON DELETE NO ACTION
Oracle Database does not have an ON UPDATE clause in referential constraint syntax, it only has an ON DELETE (optional) clause; and the only options for ON DELETE are CASCADE and SET NULL, there is no NO ACTION option. Please refer to the Oracle documentation, which is very easy to find and read.

SQL - Cannot add check constraint without checking the existing rows

I need to modify an existing constraint. I read on multiple topic that it's impossible, we need to delete and recreate it. So I've delete it and rewrote it. When trying to save it in SQL Server Management studio I got this error message :
Unable to add constraint chk_AnneeNaissance. The ALTER TABLE statement conflicted with the CHECK CONSTRAINT chk_AnneeNaissance.
I know that I have some row in my database not fulfilling this constraints but I want to add it for the next insert.
I've looked around and I found that I need to do the command myself with a NOCHECK so I'm trying this command :
ALTER TABLE [GENERAL].[dbo].[Base] WITH NOCHECK ADD CONSTRAINT chk_AnneeNaissance
But I have this error :
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'chk_AnneeNaissance'.
Can someone help me writing the right command?
ALTER TABLE [ERI_COPY_20170315].[dbo].[Base] WITH NOCHECK
ADD CONSTRAINT chk_AnneeNaissance
CHECK (
[Année de naissance] IS NOT NULL AND
[Année de naissance]>=([Date de valeur]-(80)) AND
[Année de naissance]<=([Date de valeur]-(15)) AND
len([Année de naissance])=(4)
)
It works perfectly. Thanks James Z ! I didn't know where I should put my constraints code.

sql oracle, ALTER TABLE error

Here is ERD model of my DB:
Here is create table codes i used so far:
pastebin
I have created all tables and now I'm trying to alter them to create foreign keys, but this alter doesn't work.
Alter table uskladnena_surovina add foreign key (datum_spotreby,id_dodavatela,id_suroviny) references ponukana_surovina (datum_spotreby,id_dodavatela,id_suroviny)
/
It says:
"DATUM_SPOTREBY":
00904. 00000 - "%s: invalid identifier"
You need to tell Oracle that you want to create a constraint. To do this, you need to specify add constraint after alter table .... If you don't tell Oracle what you want to add to the table, it assumes you want to add a new column.
Try
Alter table uskladnena_surovina add constraint constraint_name foreign key (datum_spotreby,id_dodavatela,id_suroviny) references ponukana_surovina (datum_spotreby,id_dodavatela,id_suroviny)
/
You also have to give the constraint a name. Feel free to change constraint_name.
Oh sorry guys,
i forgot to add datum_Spotreby into uskladnena_surovina so obviously it couldnt work, now it works

Please explain the syntax the SQLServer uses to create a check constraint

When I right click on a default constraint and I ask SQL Server to create a CREATE script for it, it generates the following code:
ALTER TABLE [dbo].[tblEventTurnJudgeStartValues] WITH NOCHECK ADD CONSTRAINT [tblEventTurnJudgeStartValues_ExecutionToggle] CHECK (([ExecutionToggle]=(1) OR [ExecutionToggle]=(0) OR [ExecutionToggle]=(-1)))
GO
ALTER TABLE [dbo].[tblEventTurnJudgeStartValues] CHECK CONSTRAINT [tblEventTurnJudgeStartValues_ExecutionToggle]
For the record, I understand the first ALTER statement but I do not understand what the the second alter statement does. Tried to google the "CHECK CONSTRAINT" phrase but only got hits on the add constraint syntax.
Thanks.
Seth
update
Thanks Joe for your answer. Found this link which helps.
http://blog.sqlauthority.com/2009/11/12/sql-server-disable-check-constraint-enable-check-constraint/
I did not know that you could enable and disable constraints. Cool!
Seth
The first statement creates the constraint, but since it is created with NOCHECK, existing data is not validated at the time of creation.
The second statement simply turns the constraint on and is technically redundant.
Personally, I'd prefer the second statement be written with the WITH CHECK option, which will validate all existing data against the constraint and will prevent the constraint from becoming untrusted.
ALTER TABLE [dbo].[tblEventTurnJudgeStartValues] WITH CHECK CHECK CONSTRAINT [tblEventTurnJudgeStartValues_ExecutionToggle]

Problem with an SQL statement

I'm having a problem with an SQL statement.
I want to activate a "ON UPDATE CASCADE" behavior for a foreign key in a table with this statement :
ALTER TABLE "DB"."RECORD" ADD CONSTRAINT "RECORD_PT_OUTIL_FK1" FOREIGN KEY ("CDE_PO")
REFERENCES "DB"."PT_OUTIL" ("CDE_PO") ON UPDATE CASCADE ENABLE;
But when i run the statement in Oracle Developer, i just get this error message : "ORA-00905 : missing keyword"
I can't find what could be this missing keyword, i tried several changes but always the same error occurs.
I reuse a code generated by Oracle Developer it self and just modify it with what i want.
This is the generated code :
ALTER TABLE "DB"."RECORD" ADD CONSTRAINT "RECORD_PT_OUTIL_FK1" FOREIGN KEY ("CDE_PO")
REFERENCES "DB"."PT_OUTIL" ("CDE_PO") ON DELETE CASCADE DISABLE;
See, i just change the end of it.
So what's the matter here ? Am i missing something ? (please don't bash if it's something obvious :) )
Thx !
Oracle does not support the ON UPDATE clause for foreign keys.
See the description of the REFERENCES clause in the manual:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/clauses002.htm#CJAIHHGC
Try by removing the DISABLE/ ENABLE at the end of your command
As per the ADD CONSTRAINT reference, there doesnt seem to be any "Enable / Disable" as part of the command.
I think it is something that your Oracle Developer is adding at the end (it being part of Oracle Syntax) and it might be causing the problem!!