You are here: Re: SQL Server trigger that fires only on update of certain field? « MsSQL Server « IT news, forums, messages
Re: SQL Server trigger that fires only on update of certain field?

Posted by Erland Sommarskog on 09/29/46 11:55

(dba_222@yahoo.com) writes:
> I'm an Oracle guy, who is being given more SQL Server assignments
> lately.
>
> I've been looking for things on the web about this, but I can't
> anything so far.
>
> In Oracle, I you can create a trigger on a table that -only- fires if
> certain fields are updated.
>
> create or replace trigger trg_some_trigger
> BEFORE insert
> OF some_field1, some_field2
> on tbl_some_table
> for each row
>
> ...
>

As Mike said, the best you can do is to check in the trigger whether
a columns was updated:

IF UPDATE(col)
BEGIN
-- Do stuff
END

But keep in mind that this not tell you whether any values in the
column were changed, only that it was mention in the SET clause of
an UPDATE statement. And for INSERT the condition is alwauys tru.

Also keep in mind that in SQL Server a trigger fires once per
statement, not once per row.

And, finally, there are no BEFORE triggers in SQL Server. Only INSTEAD OF
triggers and AFTER triggers.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

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

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