Afficher un message
Vieux 28/03/2008, 01h50   #6
Tom Cooper
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: triggers fire circulary exceed limit of 32

Thanks. You're right. Either method will work correctly, but checking
@@RowCount is a cleaner and probably more efficient way to do this.

Tom

"Hugo Kornelis" <hugo@perFact.REMOVETHIS.info.INVALID> wrote in message
news:i06ou3hft0v9p0nug407ta3ksh1vvhjvt9@4ax.com...
> On Thu, 27 Mar 2008 11:46:22 -0400, Tom Cooper wrote:
>
>>The way I would probably use to fix this in this case is just to add a
>>test
>>at the beginning of each trigger to see if the inserted table has any
>>rows,
>>e.g.,
>>If Exists (Select * From inserted) or If Not Exists (Select * From
>>inserted)

> (snip)
>
> Hi Tom,
>
> Better just test @@ROWCOUNT. Make sure it's the first statement of the
> trigger, though!
>
> I always start each trigger with
>
> CREATE TRIGGER TriggerName
> ON TableName AFTER Operation(s)
> AS
> IF @@ROWCOUNT = 0 RETURN;
> /* Rest of the code goes here */
> go
>
> I then delete the IF ... RETURN if the trigger has to do something even
> if the firing statement affected zero rows.
>
> --
> Hugo Kornelis, SQL Server MVP
> My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis



  Réponse avec citation
 
Page generated in 0,05650 seconds with 9 queries