Search This Blog

Loading...

7.07.2009

how-to drop all contraints on a table in tsql

SOURCE:
Jon Galloway


-- t-sql scriptlet to drop all constraints on a table
DECLARE @database nvarchar(50)
DECLARE @table nvarchar(50)
 
set @database = 'GenApp'
set @table = 'ParamDescriptor'
 
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

0 comments:

Post a Comment

Cool , check also:
This nice link
This nice link
This nice link

Blog Archive

My Blog List

Video Bar

Loading...

About Me

My Photo
Yordan Georgiev
It is one thing to know what to want, second to really want it, third to know how to do it, fourth to be skillful to do it, fifth to actually do it and last but not least to go on without regrets after having done it. LinkedIn Profile
View my complete profile