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.
| Author |
Topic |
|
kurtgr
Starting Member
25 Posts |
Posted - 2009-07-09 : 21:42:05
|
| Hi AllI am doing a delete trigger where i am deleting a record from a table but before i can do this i first check if this record is used in another table. If it does exist I want to return a message to my application stating that record cannot be deleted.How do I go about doing thisBelow is the CodeALTER TRIGGER [DeleteSkill] ON [dbo].[Skill] INSTEAD OF DELETEAS DECLARE @SkillId INT,@StringVariable NVARCHAR(50),@StringVar NVARCHAR(50); Select @SkillId = SkillId From DELETED --BEGIN TRANSACTION RAISERROR(N'Message', 16, 1); IF EXISTS( SELECT * FROM EmployeeSkill WHERE SkillId = @SkillId )BEGINRAISERROR('Customer has Order History. Delete failed!', 16,1)ROLLBACK TRANSACTIONENDElseBEGINdelete from skill where skillid = @SkillIdRAISERROR('Deleted Successful!', 16,1)END--COMMIT TRANSACTION Thanks In Advance |
|
|
waterduck
Aged Yak Warrior
982 Posts |
|
|
|
|
|