本文共 1467 字,大约阅读时间需要 4 分钟。
I'm changing constraints in my database and I need to drop some of them. I know that for a single constraint, the command is following:
我正在更改數據庫中的約束,我需要刪除其中一些約束。我知道對於單個約束,命令如下:
ALTER TABLE tblApplication DROP CONSTRAINT constraint1_name;
However, when I try
但是,當我嘗試
ALTER TABLE tblApplication DROP (
CONSTRAINT constraint1_name,
CONSTRAINT constraint2_name
);
it doesn't work and I need to do:
它不起作用,我需要這樣做:
ALTER TABLE tblApplication DROP CONSTRAINT constraint1_name;
ALTER TABLE tblApplication DROP CONSTRAINT constraint2_name;
Is there a way to remove more than one constraint in a single command? I'd like to avoid repeating ALTER TABLE tblApplication, just like with the ADD command:
有沒有辦法在單個命令中刪除多個約束?我想避免重復ALTER TABLE tblApplication,就像使用ADD命令一樣:
ALTER TABLE tblApplication
ADD {
CONSTRAINT contraint1_name FOREIGN KEY ... ENABLE,
CONSTRAINT contraint2_name FOREIGN KEY ... ENABLE,
};
2 个解决方案
#1
21
Yes you can. You just need to repeat 'drop constraint' per constraint. e.g.
是的你可以。您只需要為每個約束重復'drop constraint'。例如
alter table t1
drop constraint fk1
drop constraint fk2
/
Edit: I tested this against Oracle 11, and it worked fine. Don't know about older versions.
編輯:我對Oracle 11進行了測試,它運行良好。不知道舊版本。
#2
0
There is an alternative form to drop constraints related to a column in a table, also dropping the column with CASCADE:
有一種替代形式可以刪除與表中列相關的約束,同時使用CASCADE刪除列:
ALTER TABLE table1 DROP (columnName) CASCADE CONSTRAINTS;
It is tested on Oracle 11g
它在Oracle 11g上進行了測試
转载地址:http://ucevl.baihongyu.com/