Explore Courses Blog Tutorials Interview Questions
+2 votes
1 view
in SQL by (106k points)

I need to remove a highly referenced table in a SQL Server database. How can I get a list of all the foreign key constraints I will need to remove in order to drop the table?

(SQL answers preferable over clicking about in the GUI of the management studio.)

1 Answer

+3 votes
by (40.4k points)
edited by

I prefer to use sp_fkeys for a given table to query foreign keys:

EXEC sp_fkeys 'Table_Name'

Want to learn SQL from basics! Here's the right video for you on SQL provided by Intellipaat:

You can also specify the schema this way:

EXEC sp_fkeys @pktable_name = 'Table_Name', @pktable_owner = 'dbo'

If you are not specifying the schema, then use this docs as it will give you the tips on listing foreign keys referencing to the table in SQL Server.

Browse Categories