SQL Server Trigger on INSERT always ROLLED BACK -
i want create trigger not allow past client out usa
.
so code is:
create trigger location_tr on t1 insert, update begin declare @country varchar(50) set @country = (select country inserted); if @country <> 'usa' begin print 'you cant add user out of usa!' rollback transaction end else commit transaction end
so now, can't update
or insert
on table t1.
i guess i'm going wrong commit/rollback
commands. need help. thanks
the first issue trigger not support multiple rows. should use exists instead of setting value of variable. along these lines.
create trigger location_tr on t1 insert, update begin if exists(select * inserted country <> 'usa') begin print 'you cant add user out of usa!' rollback transaction end end
Comments
Post a Comment