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
  • 32,612
  • 68
  • 179
  • 322

2 Answers2

1
ALTER TABLE tablename NOCHECK CONSTRAINT all
Deepanshu Goyal
  • 2,738
  • 3
  • 34
  • 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