Why does SQL Server keep creating a DF constraint?

前端 未结 3 1749
离开以前
离开以前 2021-01-31 14:31

I\'m trying to create upgrade and backout scripts in SQL. The upgrade script adds a column like so:

IF NOT EXISTS (SELECT * FROM sys.columns WHERE Name = N\'Col         


        
3条回答
  •  天涯浪人
    2021-01-31 14:47

    Run this:

    declare @name as nvarchar(255);
    SELECT @name = name FROM dbo.sysobjects 
    WHERE name LIKE 'DF__XXX__YYY__%' and type = 'D'
    
    IF @name IS NOT NULL BEGIN
        EXEC('ALTER TABLE XXX DROP CONSTRAINT ' + @name);
    END
    

提交回复
热议问题