The target table '%.*ls' of the OUTPUT INTO clause cannot have any enabled triggers.

Error Message:
Msg 331, Level 16, State 1, Line 2
The target table ‘%.*ls’ of the OUTPUT INTO clause cannot have any enabled triggers.

Severity level:
16.

Description:
This error message appears when you try to use the OUTPUT INTO clause for a target table which has triggers enabled.

Consequences:
The T-SQL statement can be parsed, but causes the error at runtime.

Resolution:
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 have enabled triggers.

Versions:
This error message was introduced with SQL Server 2005.

Example(s):
IF OBJECT_ID (‘dbo.t’) IS NOT NULL
    DROP TABLE dbo.t;
IF OBJECT_ID (‘dbo.t2’) IS NOT NULL
    DROP TABLE dbo.t2;
   
CREATE TABLE dbo.t
    (c1 int,
    s1 varchar(20));

GO
CREATE TABLE dbo.t2
    (c1 int,
    s1 varchar(20));
GO
CREATE TRIGGER dbo.t1_i ON dbo.t2
FOR INSERT
AS
    SELECT 1;
GO

INSERT INTO dbo.t
    OUTPUT
        inserted.c1,
        inserted.s1
    INTO
        dbo.t2
SELECT 1, ‘a’;

Remarks:
In the above example we try to insert data into the table dbo.t2 via the OUTPUT INTO clause. Because dbo.t2 has enabled triggers, the error is raised.

]]>

Leave a comment

Your email address will not be published.