Monday, October 13, 2014

0 T-SQL: How to check FK constraint and remove them

Here is the T-SQL to check the FK constraint and display its name and the parent table.

select name,OBJECT_NAME(parent_object_id) from sys.objects where object_id in 
(   select fk.constraint_object_id from sys.foreign_key_columns as fk
    where fk.referenced_object_id = 
        (select object_id from sys.tables where name = 'region')
)

image

Then we can use alter table statement  to remove it from parent table.

alter table nation drop nation_region_fk

0 comments:

Post a Comment

 

SQL Panda Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates