DECLARE @ObjectName NVARCHAR(10)
DECLARE @table_name NVARCHAR(10)
SELECT @ObjectName = default_constraints.name, @table_name = tables.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 = 'EmpRole'
AND all_columns.name = 'IsVisible'
EXEC ('ALTER TABLE '+@table_name+' DROP CONSTRAINT ' + @ObjectName)
ALTER TABLE EmpRole ADD CONSTRAINT DF_EmpRoleRole_IsVisible DEFAULT 1 FOR Visible;
No comments:
Post a Comment