all groups > sql server (alternate) > june 2003 >
You're in the

sql server (alternate)

group:

Help ! How do i refer to the deleted table into a trigger statement ?


Help ! How do i refer to the deleted table into a trigger statement ? Eddy Fontaine
6/26/2003 8:41:31 PM
sql server (alternate):
Hi there,

Could somebody post some simple example how one can refer to
a column in the 'deleted' temporary table within a trigger definition ?
Should the 'deleted' and 'inserted' temp tables be declared, or they are
'implied' ?

I keep having this msg when trying to create a trigger
"The column prefix 'deleted' does not match with a table name or alias name
used in the query"

Thanks for your inputs,
Eddy.


Re: Help ! How do i refer to the deleted table into a trigger statement ? Erland Sommarskog
6/26/2003 9:49:18 PM
[posted and mailed, please reply in news]

Eddy Fontaine (eddy.fontaine@advalvas.be) writes:
[quoted text, click to view]

They are implied. You just use them.

[quoted text, click to view]

May I guess that you are using dynamic SQL? Code executed in EXEC() or
sp_executesql is not part of the trigger, but constitutes a scope on
its own.

A practical workaround is to say:

SELECT * INTO #deleted FROM deleted
SELECT * INTO #inserted FROM inserted

first in the trigger.

This can even be useful in a trigger that does not use dynamic SQL,
particular if multi-row operations are common, because you can get
better performance. The virtual tables inserted and deleted are
not very efficient when they get some size.



--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
AddThis Social Bookmark Button