Psst! Did you know DevelopmentNow is a mobile web site design agency?

Contact us for help mobilizing your site, or to sign up for our beta Mobile Web SDK!
all groups > sqlserver server > february 2006 >

sqlserver server : SQL2005 - not documented triggers behavior change


RADl0PASlV
2/28/2006 4:08:26 PM
I have a simple table with trigger, for example:

CREATE TABLE T(V VARCHAR(100) NULL)
GO
CREATE TRIGGER TR ON T FOR INSERT AS
ROLLBACK
GO
INSERT T(V)VALUES('X')

On MSSQL7 or MSSQL2000 INSERT runs without any messages. On MSSQL2005 INSERT
states:

Server: Msg 3609, Level 16, State 1, Line 1
The transaction ended in the trigger. The batch has been aborted.

This is not documented triggers behavior change. This can break
compatibility of older applications. Changing database compatibility level
not helps. All ideas and suggestions are welcome.

tested on:
Microsoft SQL Server 2005 Standard Edition x86 (build 9.00.1399.06)

RADl0PASlV
/sorry my awful English/

Sreejith G
3/1/2006 2:20:28 AM
FROM 2005 BOL

If a trigger completes execution with an @@TRANCOUNT = 0, an error 3609
occurs and the batch is terminated. For this reason, inside of triggers it is
advisable to avoid using ROLLBACK TRANSACTION, which resets @@TRANCOUNT to 0,
and COMMIT TRANSACTION, which may decrement @@TRANCOUNT to 0. Issuing a BEGIN
TRANSACTION statement after a rollback will stop the error from being raised,
but this could cause problems with application logic.


Instead of using ROLLBACK TRANSACTION, the SAVE TRANSACTION statement can be
used to execute a partial rollback in a trigger.


--
Thanks,
Sree
[Please specify the version of Sql Server as we can save one thread and time
asking back if its 2000 or 2005]



[quoted text, click to view]
AddThis Social Bookmark Button