Raising error in Trigger:
here iam creating two tables
my requirement is when there are records in job
we have raise an error not to delete from employee table
select * from job
select * from employee123
create trigger Raiseerrortrigger on Employee123
for delete
as
if(select count(*) from job)>0
begin
RAISERROR 50009 'cannot delete an employee'
ROLLBACK TRANSACTION
RETURN
end
RESULT
now if i try to delete a reocrd from employee table then
if the job table is having any records then it wont allow to
delete from employee table .trigger will restrict
No comments:
Post a Comment