T-SQL删除多重约束,如果存在

问题描述 投票:0回答:1

如何将其应用于来自不同表的多个约束:

IF (OBJECT_ID('DF_Constraint') IS NOT NULL)
BEGIN
    ALTER TABLE [dbo].[tableName]
    DROP CONSTRAINT DF_Constraint
END

没有像这样为我工作:

IF (OBJECT_ID('DF_Constraint') IS NOT NULL)
AND (OBJECT_ID('DF_Constraint2') IS NOT NULL)
BEGIN
    ALTER TABLE [dbo].[tableName] DROP CONSTRAINT DF_Constraint;
    ALTER TABLE [dbo].[tableName2] DROP CONSTRAINT DF_Constraint2;
END
sql-server tsql constraints ssms
1个回答
0
投票

尝试这样的事情:

© www.soinside.com 2019 - 2024. All rights reserved.