How to Alter Constraint

后端 未结 2 842
再見小時候
再見小時候 2020-11-30 00:52

SQL How to Alter Constraint

Below is 1 of my constraint

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


        
相关标签:
2条回答
  • 2020-11-30 01:27

    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

    0 讨论(0)
  • 2020-11-30 01:34

    No. We cannot alter the constraint, only thing we can do is drop 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 constraint

    Alter Table Table add constraint [Primary Key] Primary key(Column1,Column2,.....)
    
    0 讨论(0)
提交回复
热议问题