Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Alter Constraint

Tags:

sql

oracle

SQL How to Alter Constraint

Below is 1 of my constraint

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

I want to add in

ON DELETE CASCADE 

to the constraint above.

How do i alter that existing constraint ACTIVEPROG_FKEY1 and add

ON DELETE CASCADE 

to constraint ACTIVEPROG_FKEY1

Consider ACTIVEPROG_FKEY1 is at Table ACTIVEPROG

like image 404
user1777711 Avatar asked Nov 06 '12 05:11

user1777711


People also ask

How do you alter a constraint?

The basic syntax of ALTER TABLE to ADD UNIQUE CONSTRAINT to a table is as follows. ALTER TABLE table_name ADD CONSTRAINT MyUniqueConstraint UNIQUE(column1, column2...); The basic syntax of an ALTER TABLE command to ADD CHECK CONSTRAINT to a table is as follows.

Can we alter constraints in SQL?

You can not alter constraints ever but you can drop them and then recreate.

Can we modify a constraint?

An existing constraint cannot be modified. To define another column, or set of columns, as the primary key, the existing primary key definition must first be dropped, and then re-created.

Can we alter constraint in Oracle?

You can't update the constraint itself. If you want to change the values (new lower or upper bounds), you need to drop and recreate it: alter table hr.


1 Answers

You can not alter constraints ever but you can drop them and then recreate.

Have look on 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

like image 160
user1819920 Avatar answered Oct 04 '22 09:10

user1819920