|
Posted by Erland Sommarskog on 09/30/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]
|