Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Archives: October 2011

Remove All Foreign Keys

To clear test data from a database we could use truncate commands but sometimes we need to get rid of foreign keys.

we could get constaint list from INFORMATION_SCHEMA.TABLE_CONSTRAINTS table.

for example :

we could remove foreign key by using this table and the following query.

while(exists(select 1 from INFORMATION_SCHEMA.TABLE_CONSTRAINTS…

Read more

2 comments, 12,098 reads

Posted in SQL Server Tips on 11 October 2011