My doubt is when we perform any task in case of any error we will get the message like this
Msg 2627, Level 14, State 1, Procedure rec_ins, Line 3
Violation of PRIMARY KEY constraint 'PK_emp'. Cannot insert duplicate key in object 'dbo.emp'.
I want to suppress the message generated by the database is it possible or not . In case of yes how to handle it
waiting for valuable reply
Baba
If you use sql server 2005 use the try..catch block.
Code Snippet
Begin Try
Insert Into YourTable Values(Yourvalues)
End Try
Begin Catch
End Catch
If you use sql server 2000 you can't suppress the message. You have to validate the data while inserting...
Code Snippet
Insert Into Yourtable
Select Yourvalues Where
Not Exists (Select 1 From YourTable With(Nolock) Where PrimaryKeyColumn=PrimaryKeyValue)
|||Thank u for u r reply
No comments:
Post a Comment