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
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