You are here: Re: Accessing which data caused a trigger to fire « MsSQL Server « IT news, forums, messages
Re: Accessing which data caused a trigger to fire

Posted by Dan Guzman on 02/28/07 13:07

There are 2 pseudo-tables available in trigger code: "deleted" and
"inserted". When a trigger is fired by an UPDATE statement, the "deleted"
table contains images of the rows before the update and the "inserted" table
contain the row images after the update. In your update trigger code, you
can do something like:

INSERT INTO Y.dbo.B (Column1, Column2)
SELECT Column1, Column2
FROM inserted

In a trigger fired by a DELETE statement, the "deleted" table contains the
rows just deleted and the "inserted" table is empty. Similarly, when a
trigger is fired by an INSERT statement, the "inserted" table contains the
rows just inserted and the "deleted" table in empty. See the Books Online
for details.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"jcandersen" <jca@dse.dk> wrote in message
news:1172660503.230464.291380@8g2000cwh.googlegroups.com...
> Hi.
>
> I need to make a trigger which fires when after an UPDATE is done on
> table A in database X. The trigger must perform a statement which
> copies some of the data from the update to table B in database Y on
> the same server.
> My question is: Can I access the data which caused the trigger to fire
> or just get an indication of which entry in table A had been updated?
>
> Best Regards
> Jens Christian Andersen.
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация