如何将此应用于来自不同表的多个约束:
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
答案 0 :(得分:0)
尝试这样的事情:
IF OBJECT_ID('DF_Constraint') IS NOT NULL
ALTER TABLE [dbo].[tableName] DROP CONSTRAINT DF_Constraint;
IF OBJECT_ID('DF_Constraint2') IS NOT NULL
ALTER TABLE [dbo].[tableName2] DROP CONSTRAINT DF_Constraint2;
这样你可以删除每个约束(如果它存在)(你不需要同时删除每个约束)。