How to change restrictions

SQL How to change a constraint

Below is 1 of my limitations

CONSTRAINT ACTIVEPROG_FKEY1 FOREIGN KEY(ActiveProgCode) REFERENCES PROGRAM(ActiveProgCode), 

I want to add

 ON DELETE CASCADE 

to the above limitation.

How do I change an existing ACTIVEPROG_FKEY1 constraint and add

 ON DELETE CASCADE 

to limit ACTIVEPROG_FKEY1

Consider ACTIVEPROG_FKEY1 in the ACTIVEPROG table

+55
sql oracle
Nov 06 '12 at 5:24
source share
2 answers

You cannot change restrictions at any time, but you can drop them and then recreate them.

Look at this

 ALTER TABLE your_table DROP CONSTRAINT ACTIVEPROG_FKEY1; 

and then recreate it with ON DELETE CASCADE , like this

 ALTER TABLE your_table add CONSTRAINT ACTIVEPROG_FKEY1 FOREIGN KEY(ActiveProgCode) REFERENCES PROGRAM(ActiveProgCode) ON DELETE CASCADE; 

hope this help

+84
Nov 06
source share

No. We cannot change the restriction, only we can do is reset and recreate it

 ALTER TABLE [TABLENAME] DROP CONSTRAINT [CONSTRAINTNAME] 

Foreign key constraint

 Alter Table Table1 Add Constraint [CONSTRAINTNAME] Foreign Key (Column) References Table2 (Column) On Update Cascade On Delete Cascade 

Primary key restriction

 Alter Table Table add constraint [Primary Key] Primary key(Column1,Column2,.....) 
+6
Nov 06 '12 at 5:28
source share



All Articles