In previous versions of SQL Server you would handle exceptions by checking the @@error global variable immediately after an INSERT, UPDATE or DELETE, and then perform some corrective action if @@error did not equal zero.
SQL Server 2005 provides structured exception handing through TRY CATCH block as other programming language like JAVA, C# etc.
RAISERROR ('A problem is raised', 16,1)
SELECT ERROR_NUMBER() as ERROR_NUMBER,
ERROR_SEVERITY() as ERROR_SEVERITY,
ERROR_STATE() as ERROR_STATE,
ERROR_MESSAGE() as ERROR_MESSAGE
returns the number of the errors.
returns the severity.
returns the error state number.
returns the name of the stored procedure or trigger where the error occurred.
returns the line number inside the routine that caused the error.
returns the complete text of the error message. The text includes the values supplied for any substitutable parameters, such as lengths, object names and times etc.
Asked In: Many Interviews |