You are here: Re: Trigger Error « MsSQL Server « IT news, forums, messages
Re: Trigger Error

Posted by Erland Sommarskog on 10/01/24 11:17

coosa (coosa76@gmail.com) writes:
> Can u explain your code? especially the part:
> DECELARE @affected TABLE (category_id int NOT NULL)
> INSERT @affected(category_id)
> SELECT category_id
> FROM inserted

First I declare a table variable. I could also have created a temp
table, but my experience that for triggers table variables are better.
(Whether to use temp tables or table variables is a delicate choice.
Sometimes, table variables are better, sometimes temp tables are
better.)

Next I insert the id:s of all rows that were affected by the UPDATE
statement.

You can read about table variables in Books Online inder the DECLARE topic
in the Transact-SQL Reference. In the book "Creating and maintaing
Databases", there is a section "Enforcing Business Rules with Triggers".

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

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp

 

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

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