使用外键删除 table
Drop table with foreign key
我正在尝试此代码
Drop Table Inventory
我收到错误:
Could not drop object 'Inventory' because it is referenced by a
FOREIGN KEY constraint.
使用这个
DROP TABLE Inventory CASCADE CONSTRAINTS;
首先你必须 Drop
table 的约束,然后 table
SELECT
'ALTER TABLE ' + OBJECT_SCHEMA_NAME(parent_object_id) +
'.[' + OBJECT_NAME(parent_object_id) +
'] DROP CONSTRAINT ' + name
FROM sys.foreign_keys
WHERE referenced_object_id = object_id('Inventory')
Drop Table Inventory
您需要先删除约束..
ALTER TABLE [dbo].[t2] DROP CONSTRAINT [foreign key constraint]
然后你可以删除 table
Drop table t1
试试这个
ALTER TABLE Inventory NOCHECK CONSTRAINT all
DROP TABLE Inventory
从子 table 中删除外键约束,然后删除主 table
我正在尝试此代码
Drop Table Inventory
我收到错误:
Could not drop object 'Inventory' because it is referenced by a FOREIGN KEY constraint.
使用这个
DROP TABLE Inventory CASCADE CONSTRAINTS;
首先你必须 Drop
table 的约束,然后 table
SELECT
'ALTER TABLE ' + OBJECT_SCHEMA_NAME(parent_object_id) +
'.[' + OBJECT_NAME(parent_object_id) +
'] DROP CONSTRAINT ' + name
FROM sys.foreign_keys
WHERE referenced_object_id = object_id('Inventory')
Drop Table Inventory
您需要先删除约束..
ALTER TABLE [dbo].[t2] DROP CONSTRAINT [foreign key constraint]
然后你可以删除 table
Drop table t1
试试这个
ALTER TABLE Inventory NOCHECK CONSTRAINT all
DROP TABLE Inventory
从子 table 中删除外键约束,然后删除主 table