Joh*_*nak 11 sql database oracle constraints
我正在更改数据库中的约束,我需要删除其中的一些约束.我知道对于单个约束,命令如下:
ALTER TABLE tblApplication DROP CONSTRAINT constraint1_name;
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试
ALTER TABLE tblApplication DROP (
CONSTRAINT constraint1_name,
CONSTRAINT constraint2_name,
CONSTRAINT constraint3_name
);
Run Code Online (Sandbox Code Playgroud)
它不起作用,我需要这样做:
ALTER TABLE tblApplication DROP CONSTRAINT constraint1_name;
ALTER TABLE tblApplication DROP CONSTRAINT constraint2_name;
ALTER TABLE tblApplication DROP CONSTRAINT constraint3_name;
Run Code Online (Sandbox Code Playgroud)
有没有办法在单个命令中删除多个约束?我想避免重复ALTER TABLE tblApplication,就像ADD命令一样:
ALTER TABLE tblApplication ADD (
CONSTRAINT contraint1_name FOREIGN KEY ... ENABLE,
CONSTRAINT contraint2_name FOREIGN KEY ... ENABLE,
CONSTRAINT contraint3_name FOREIGN KEY ... ENABLE
);
Run Code Online (Sandbox Code Playgroud)
Sod*_*ved 23
是的你可以.您只需要为每个约束重复'drop constraint'.例如
alter table t1
drop constraint fk1
drop constraint fk2
/
Run Code Online (Sandbox Code Playgroud)
编辑:我针对Oracle 11进行了测试,它运行良好.不知道旧版本.