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
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.
You can not alter constraints ever but you can drop them and then recreate.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With