DROPING ALL THE CONSTRAINTS ON A TABLE
-- T-SQL SCRIPTLET TO DROP ALL CONSTRAINTS ON A TABLE
DECLARE @database nvarchar(50)
DECLARE @table nvarchar(50)
set @database = 'TEST_DB'
set @table = 'TEST_TABLE'
DECLARE @sql nvarchar(255)
WHILE EXISTS(select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where constraint_catalog = @database and table_name = @table)
BEGIN
select @sql = 'ALTER TABLE ' + @table + ' DROP CONSTRAINT ' + CONSTRAINT_NAME
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
where constraint_catalog = @database and
table_name = @table
exec sp_executesql @sql
END
DECLARE @database nvarchar(50)
DECLARE @table nvarchar(50)
set @database = 'TEST_DB'
set @table = 'TEST_TABLE'
DECLARE @sql nvarchar(255)
WHILE EXISTS(select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where constraint_catalog = @database and table_name = @table)
BEGIN
select @sql = 'ALTER TABLE ' + @table + ' DROP CONSTRAINT ' + CONSTRAINT_NAME
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
where constraint_catalog = @database and
table_name = @table
exec sp_executesql @sql
END
Comments
Post a Comment