tsql - RAISEERROR or throw in trigger to rollback DML statement -
just have throw or raiseerror in trigger below
if object_id('sales.orderdetails_aftertrigger', 'tr') not null drop trigger sales.orderdetails_aftertrigger; go create trigger sales.orderdetails_aftertrigger on sales.orderdetails after insert, update begin if @@rowcount = 0 return; set nocount on; -- check rows if exists(...) begin raiserror ('this error message not displayed', 10, 1 ) end end go
if raiseerror thrown in trigger prevent dml statement being rolled back?
just notice still getting rows inserted when happens.
check out remarks section in raise error page microsoft http://msdn.microsoft.com/en-us/library/ms178592.aspx
"when raiserror run severity of 11 or higher in try block, transfers control associated catch block"
your throwing 10 control not go catch statement. that'll calling code flow if trying stop there (not shown hard tell).
but!! made comment rows still inserted. suspect should perhaps using insert update trigger not "after" trigger.
since throw 10 rows inserted , won't break transaction.
sorry can't more precise kind of hard without knowing context calling insert/update statement triggering trigger
Comments
Post a Comment