SQL 如何改变约束

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13244889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 11:57:58  来源:igfitidea点击:

How to Alter Constraint

sqloracle

提问by user1777711

SQL How to Alter Constraint

SQL 如何改变约束

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

我如何更改现有约束 ACTIVEPROG_FKEY1 并添加

ON DELETE CASCADE

to constraint ACTIVEPROG_FKEY1

约束 ACTIVEPROG_FKEY1

Consider ACTIVEPROG_FKEY1 is at Table ACTIVEPROG

考虑 ACTIVEPROG_FKEY1 在表 ACTIVEPROG

回答by user1819920

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 CASCADElike this

然后ON DELETE CASCADE像这样重新创建它

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

hope this help

希望这有帮助

回答by andy

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,.....)