Click here to Skip to main content
15,895,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
--T-Sql Block
go
delete from authors where au_id='172-32-1176'
declare @d int =@@ERROR
update authors set au_lname=NULL where au_id='172-32-1176'
declare @u int =@@ERROR
if @d<>0
print 'Error occured in delete'
if @u<>0
print 'Error occured in update'
go


The output i got is given below. Here along with the custom error messages that i am raising using the @@Error, I am also getting the system error messages. So is there any way we can suppress the system error messages

Quote:

Msg 547, Level 16, State 0, Line 1
The DELETE statement conflicted with the REFERENCE constraint "FK__titleauth__au_id__0519C6AF". The conflict occurred in database "pubs", table "dbo.titleauthor", column 'au_id'.
The statement has been terminated.
Msg 515, Level 16, State 2, Line 3
Cannot insert the value NULL into column 'au_lname', table 'pubs.dbo.authors'; column does not allow nulls. UPDATE fails.
The statement has been terminated.
Error occured in delete
Error occured in update
Posted

AFAIK there is no general way to suppress error messages in SQL, with the exception of overflow and related arithmetic errors.
 
Share this answer
 
You can use TRY CATCH block in your TSQL. Please read these pages for more info :

http://www.4guysfromrolla.com/webtech/041906-1.shtml[^]

http://msdn.microsoft.com/en-us/library/ms179296.aspx[^]

And find more about this topic by using Google.

Hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900