Explore Courses Blog Tutorials Interview Questions
+2 votes
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.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

29.3k questions

30.6k answers


104k users

Browse Categories