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)
 Exit running trigger

Author  Topic 

allan_houston
Starting Member

18 Posts

Posted - 2006-07-16 : 17:16:10
Hello

Is it possible to exit and abort the transaction in a trigger and how?

Like

create trigger trig_delDept
on dept
for delete
as
declare @loc varchar(20)
select @loc = loc from deleted

if @loc = 'SAN FRANCISCO'

--exit code


kind regards
a.h.

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2006-07-16 : 17:23:19
The deleted table contains all the rows that were deleted, which can be more than one.

You could put something like this in the trigger:

if exists(select * froom deleted where loc = 'SAN FRANSISCO')
begin
rollback
raiserror('Deletion of SAN FRANSISCO not allowed',16,1)
end

rockmoose
Go to Top of Page

allan_houston
Starting Member

18 Posts

Posted - 2006-07-16 : 17:36:07
Thx rockmoose.

It helped
Go to Top of Page
   

- Advertisement -