Triggers in SQL Server -


there 2 table table_trigger , table_trigger1.i have created trigger on table_trigger1. works perfectly.below trigger script -

create trigger test_trigger on table_trigger1  instead of insert  set nocount on  insert table_trigger1(firstname) select firstname inserted i.firstname in (select firstname table_trigger) 

when condition true, message (1 row(s) affected) , value save in table.but when condition false, time message (1 row(s) affected) , value not save in table.

my question - if condition false , value don't save in table why got (1 row(s) affected) message. meaning of message.

thanks in advance.

in nutshell, "rows affected" original insert ignorant of what's going on behind scenes in trigger. passes 1 row through , considers row "affected."

i tried find documentation up. closest come documentation on sqlcommand.executenonquery, states:

for update, insert, , delete statements, return value number of rows affected command. when trigger exists on table being inserted or updated, return value includes number of rows affected both insert or update operation , number of rows affected trigger or triggers.

of course, set nocount on in trigger suppressing return of number of rows affected within trigger, you're seeing result of original insert statement.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -