November 4, 2014 at 11:05 pm
Dear,
I have created a "After Insert" trigger in one of my tables. It will raise an error message if conditions are not met. When I click on "Save" button, no error message appears but it prevents transaction from inserting rows.
Please guide me the way so that an error message appears if conditions are not met.
Thanks
November 5, 2014 at 4:36 am
Don't use triggers to restrict allowed data in a table. Use CHECK constraints instead.
If you insist using a trigger, use ROLLBACK to prevent the changes to the destination table. RAISERROR won't always be enough.
What you display in the application is totally up to you, but you should get the error if raised correctly. Be aware that severity below 10 is interpreted as a PRINT message and isn't forwarded to the application as a real error.
-- Gianluca Sartori
November 5, 2014 at 10:16 pm
I have used rollback and also require to display an error message. But the message is not appearing. I have used the following code.
begin
RAISERROR ('Sorry!You have entered more discount',16,1);
ROLLBACK;
end
November 6, 2014 at 1:06 am
Quick suggestion, add WITH NOWAIT to the RAISERROR
😎
BEGIN
BEGIN TRAN;
RAISERROR ('Sorry!You have entered more discount',16,1) WITH NOWAIT;
ROLLBACK;
END
November 7, 2014 at 8:29 am
I tried all the way out but in vain. I am not getting any clue.
November 7, 2014 at 9:50 pm
shohelr2003 (11/4/2014)
Dear,I have created a "After Insert" trigger in one of my tables. It will raise an error message if conditions are not met. When I click on "Save" button, no error message appears but it prevents transaction from inserting rows.
Please guide me the way so that an error message appears if conditions are not met.
Thanks
Do you have anything in the GUI to actually capture and report the error?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply