DECLARE @EmpName NVARCHAR(100)
SELECT @EmpName = default_constraints.name
FROM
sys.all_columns
INNER JOIN
sys.tables
ON all_columns.object_id = tables.object_id
INNER JOIN
sys.schemas
ON tables.schema_id = schemas.schema_id
INNER JOIN
sys.default_constraints
ON all_columns.default_object_id = default_constraints.object_id
WHERE
schemas.name = 'dbo'
AND tables.name = EmpTable
AND all_columns.name = 'EmpGuid'
EXEC ('ALTER TABLE EmpTable DROP CONSTRAINT ' + @EmpName)
Alter Table EmpTable drop column EmpGuid
No comments:
Post a Comment