我们支持的各种客户运行的脚本的一部分添加了外键,但是在运行脚本的这一部分时我不想添加其中一个外键,因为有些客户在他们的设置中没有这个。如何从下面的代码中删除FK6。我在下面的外键FK6上尝试了DROP但是语法错误。
IF OBJECT_ID('FK2') IS NULL
BEGIN
ALTER TABLE [table_1] ADD
CONSTRAINT [FK2] FOREIGN KEY
(
[reason_gen]
) REFERENCES [table_1] (
[field_1]
) NOT FOR REPLICATION,
CONSTRAINT [FK3] FOREIGN KEY
(
[field_2],
[field_3]
) REFERENCES [table_2] (
[field_4],
[field_5]
) NOT FOR REPLICATION,
CONSTRAINT [FK4] FOREIGN KEY
(
[res_code_gen]
) REFERENCES [table_3] (
[field_6]
) NOT FOR REPLICATION,
CONSTRAINT [FK5] FOREIGN KEY
(
[field_7],
[field_8]
) REFERENCES [table_4] (
[field_7],
[field_8]
) NOT FOR REPLICATION,
ALTER TABLE [table_1] DROP
CONSTRAINT [FK6] FOREIGN KEY
(
[field_9]
) REFERENCES [ftable_5] (
[field_10]
) NOT FOR REPLICATION
END
答案 0 :(得分:1)
删除外键的语法只是:
ALTER TABLE [table_1] DROP CONSTRAINT [FK6]
答案 1 :(得分:0)
这是哪个数据库? Oracle,MYSQL,SQL Server?
对于Oracle,语法为:
ALTER TABLE table_name
drop CONSTRAINT constraint_name;