0

Is there is any way in TSQL to Drop a table with it's all Foreign Keys Constraint? I have search a lot but could not find any?

Imran Qadir Baksh - Baloch
  • 30,546
  • 66
  • 170
  • 302

2 Answers2

1
ALTER TABLE tablename NOCHECK CONSTRAINT all
Deepanshu Goyal
  • 2,658
  • 3
  • 33
  • 61
1

To get all foreign key relationships referencing your table, you could use this SQL (if you're on SQL Server 2005 and up):

Use Below Script

SELECT * FROM sys.foreign_keys WHERE referenced_object_id = object_id(TableName)

SELECT 'ALTER TABLE ' + OBJECT_NAME(parent_object_id) + ' DROP CONSTRAINT ' + name FROM sys.foreign_keys WHERE referenced_object_id = object_id(TableName)

Munir Vora
  • 51
  • 11