hi all
i've created a trigger that is suppose to prevent a record being deleted if it exists in another table. My syntax seems ok. When I executed it it went through all its checks and printed the message to the screen like it is meant to.
The problem is that it deleted the record anyway.
Here is my syntax, what am I missing:
CREATE TRIGGER [COMMON_CATEGORY] ON [dbo].[PROB_CATEGORY]
FOR DELETE
AS
declare @catcode varchar(20);
declare @cmcode varchar(20)
select @catcode = p.category_code from prob_category p, deleted d
where p.category_code = d.category_code
select @cmcode = category_code from common_problem
if @catcode = @cmcode
ROLLBACK TRANSACTION
print
'The category you attempted to delete has a common problem associated to it'
Thanks
John
i've created a trigger that is suppose to prevent a record being deleted if it exists in another table. My syntax seems ok. When I executed it it went through all its checks and printed the message to the screen like it is meant to.
The problem is that it deleted the record anyway.
Here is my syntax, what am I missing:
CREATE TRIGGER [COMMON_CATEGORY] ON [dbo].[PROB_CATEGORY]
FOR DELETE
AS
declare @catcode varchar(20);
declare @cmcode varchar(20)
select @catcode = p.category_code from prob_category p, deleted d
where p.category_code = d.category_code
select @cmcode = category_code from common_problem
if @catcode = @cmcode
ROLLBACK TRANSACTION
'The category you attempted to delete has a common problem associated to it'
Thanks
John