Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Rollback in a trigger

Author  Topic 

tal_olier
Starting Member

13 Posts

Posted - 2002-08-27 : 09:31:44
Hello,

I would like to create a trigger (instead of insert) on MS-SQL Server table in a way that if something happens (say x=1) I would like to rollback the insert.

In the trigger code I have

...
IF (x=1)
BEGIN
RAISERROR ('error, please contact support', 2/*2=EXUSER*/, 1/*default state*/)
ROLLBACK TRANSACTION <---------
END
...

My question is:
I can use ROLLBACK or ROLLBACK TRANSACTION
In the docs I have read that the ROLLBACK rollbacks to the far most old begin transaction but when I test it it rollbacks the same using ROLLBACK TRANSACTION.

I have tested it using:
begin transaction t1
update tx set c1 = c1 + 1
INSERT INTO test_table values(.....)
commit transaction t1

And both the update and the insert are rolled back on both cases.


- Any idea why or what am I missing ?



Regards,

Tal Olier (otal@mercury.co.il)



nr
SQLTeam MVY

12543 Posts

Posted - 2002-08-27 : 09:53:18
Looks familiar

duplicate post - see under developer

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -