T-SQL Tutorial

Msg 3726 Level 16 - Could not drop object


On Transact SQL language the Msg 3726 Level 16 - Could not drop object because it is referenced by a FOREIGN KEY constraint.

Msg 3726 Level 16 Example:

Create tables

USE model;
GO
create table Test_1
(id int not null primary key,
name varchar(500) not null);
GO
create table Test_2
(id int not null primary key,
name varchar(500) not null,
constraint FK_TestID
foreign key (id) references Test_1(id));
GO

Invalid statement:

USE model;
GO
DROP TABLE Test_1;
GO

Message
Msg 3726, Level 16, State 1, Line 3
Could not drop object 'Test_1' because it is referenced by a FOREIGN KEY constraint.

Correct statement:

USE model;
GO
DROP TABLE Test_2;
GO
DROP TABLE Test_1;
GO

Other error messages: