Hello,
I have a table T1 and on this table I have an insert trigger. In the trigger I need to check if T1.ID and T1.Type='xyz' together are duplicated or not (duplicate dhcek on two columns), if yes return error from trigger. There might be T1.ID and T1.Type='abc' duplicated, that is fine.
Hi
I don't think you can return error from trigger directly to your application.
You can set a flag to indicate error happened.
CREATE TRIGGER trgAfterInsertOn T1FOR INSERTASBEGIN declare @.idint declare @.typevarchar(32)SELECT @.id=id,@.type=typeFROM INSERTEDIFNOT EXISTS(SELECT *FROM T1WHERE T1.id=@.id )begin if (@.type='xyz')begin/* insert error flag */end endEND
No comments:
Post a Comment