![]() |
| ||
| Error in Trigger Using TRY CATCH AND IF ELSE Hi all, I am creating a trigger which should be triggered on insert to BOOKISSUEDETAILS table. I want to alter the table LIBRARYBOOKDETAILS table only if the Inventory column value is greater than 1. Initially I have created the trigger in the following way. But now I want to alter the Trigger to include the condition(Inventory > 1) and use the Try catch block to raise error. I used the following code snippet to alter the trigger, but it is generating the error: alter trigger trg_InsertInBookIssuedDetails on BOOKISSUEDDETAILS Error Message: Msg 156, Level 15, State 1, Procedure trg_InsertInBookIssuedDetails, Line 19 Incorrect syntax near the keyword 'else'. Msg 156, Level 15, State 1, Procedure trg_InsertInBookIssuedDetails, Line 25 Incorrect syntax near the keyword 'end'. Can anyone let me know the error? and the changes I should make to perform the desired task with condition. Please help me out in identifying the error. Thanks in advance. |
| ||
| Re: Error in Trigger Using TRY CATCH AND IF ELSE Try this: Create trigger trg_InsertInBookIssuedDetails on BOOKISSUEDDETAILS Also -- Please use [code] tags in the future, not <code> |
| ||
| Re: Error in Trigger Using TRY CATCH AND IF ELSE Quote:
Thanks for your reply. But since I am a beginner I have a doubt with RaisError statement. Can you tell me why are we writing 16,-1? What does this indicate? What can be replaced instead of this? Sorry I am asking so many doubts but I am learning SQL server on my own and I have found this forum very useful specifically for MS SQL SERVER. Thanks for your reply |
| ||
| Re: Error in Trigger Using TRY CATCH AND IF ELSE The two parameters are severity and state. The severity of the error dictates how MSSQL will handle the error. See http://doc.ddart.net/mssql/sql70/ra-rz_1.htm Here is a quote: severity I hope this answers your question and I'm glad you find daniweb useful. Please be sure to start a new thread when you have new questions and mark old threads as solved. It gives the solvers here incentive to help! |
| ||
| Re: Error in Trigger Using TRY CATCH AND IF ELSE Quote:
Thanks for your prompt reply!! |
| All times are GMT -4. The time now is 8:06 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC