Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in SQL by (20.3k points)

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

1 Answer

0 votes
by (40.7k points)

You can not alter constraints ever but you can drop them and then recreate like 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;

Related questions

0 votes
2 answers
0 votes
1 answer
asked Jul 16, 2019 in SQL by Tech4ever (20.3k points)
0 votes
3 answers
asked Dec 29, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...