- Discover whether there is a constraint;
SELECT @ConstraintName = [name]
FROM sys.objects o
WHERE o.[parent_object_id]=OBJECT_ID('Schema.TableName')AND o.type='D'
AND o.[name] LIKE '%First5LettersOfColumnName%'
- If there is, remove it;
EXECUTE ('ALTER TABLE Schema.TableName
DROP CONSTRAINT ' + @ConstraintName)
GO
- Remove the column
AND [object_id]=OBJECT_ID('Schema.TableName'))
ALTER TABLE Schema.TableName
GO
No comments:
Post a Comment