Msg 332, Level 16, State 1, Line 6
The target table ‘%.*ls’ of the OUTPUT INTO clause cannot be on either side of a (primary key, foreign key) relationship. Found reference constraint ‘%ls’.
This error message appears when you try to use the OUTPUT INTO clause for a target table that appears on either side of a PRIMARY KEY – FOREIGN KEY relationship.
The T-SQL statement can be parsed, but causes the error at runtime.
Errors of the Severity Level 16 are generated by the user and can be fixed by the SQL Server user. The statement cannot be executed this way. The target table of the OUTPUT INTO clause cannot be on either side of a PRIMARY KEY – FOREIGN KEY relationship.
This error message was introduced with SQL Server 2005.
IF OBJECT_ID (‘dbo.t’) IS NOT NULL
DROP TABLE dbo.t;
IF OBJECT_ID (‘dbo.t2’) IS NOT NULL
DROP TABLE dbo.t2;
IF OBJECT_ID (‘dbo.t3’) IS NOT NULL
DROP TABLE dbo.t3;
CREATE TABLE dbo.t
CREATE TABLE dbo.t2
(c1 int PRIMARY KEY,
CREATE TABLE dbo.t3
CONSTRAINT FK_t3_t2 FOREIGN KEY (c1) REFERENCES dbo.t2(c1));
INSERT INTO dbo.t
SELECT 1, ‘a’;
In the above example we try to insert data into the table dbo.t2 via the OUTPUT INTO clause. Because dbo.t2 appears on the PRIMARY KEY side of a PRIMARY KEY – FOREIGN KEY relation, the error is raised.