tags:

views:

110

answers:

1

I am trying to find impact of doing DDL statement against deleted and inserted logical tables inside table trigger. I have:

CREATE TRIGGER [Trigger52]
ON [dbo].[Table1]
FOR DELETE, INSERT, UPDATE 
AS 
BEGIN
     create table inserted (c1 int)
     select * from inserted                        
END

When it is triggered, I expected to get an error. Instead, it seems to ignore create table statement entirely and select rows that have been inserted.

Is there a documentation describing this behavior or explanation?

A: 

Inside triggers there are always two pseudo-tables existing: inserted and deleted. See Using the inserted and deleted Tables:

SQL Server automatically creates and manages these tables. You can use these temporary, memory-resident tables to test the effects of certain data modifications and to set conditions for DML trigger actions. You cannot directly modify the data in the tables or perform data definition language (DDL) operations on the tables.

Remus Rusanu