Hi Friends.........
Can you tell me that when Raiseerror is found? and how we deal with it.
thanks.......
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Chintan RathodPosted Dec 26, 2011, 10:57 PM
Syntax:
RAISERROR ( { msg_id | msg_str | @local_variable } { ,severity ,state } [ ,argument [ ,...n ] ] ) [ WITH option [ ,...n ] ]
where,
msg_id
Is a user-defined error message number stored in the sys.messages catalog view using sp_addmessage.
msg_str
Is a user-defined message with formatting similar to the printf function in the C standard library.
@local_variable
Is a variable of any valid character data type that contains a string formatted in the same manner as msg_str.
@local_variablemust be char or varchar, or be able to be implicitly converted to these data types.
severity
Is the user-defined severity level associated with this message. When using msg_id to raise a user-defined message created using sp_addmessage, the severity specified on RAISERROR overrides the severity specified in sp_addmessage.
Severity levels from 0 through 18 can be specified by any user. Severity levels from 19 through 25 can only be specified by members of the sysadmin fixed server role or users with ALTER TRACE permissions. For severity levels from 19 through 25, the WITH LOG option is required.stateIs an integer from 0 through 255. Negative values or values larger than 255 generate an error.
argument
Are the parameters used in the substitution for variables defined in msg_str or the message corresponding to msg_id.
Option
Is a custom option for the error and can be one of the values in the following argument.
LOG, NOWAIT, SETERRORRemark:
The error is returned to the caller if RAISERROR is run:
- Outside the scope of any TRY block.
- With a severity of 10 or lower in a TRY block.
- With a severity of 20 or higher that terminates the database connection.
RAISERROR only generates errors with state from 1 through 127. Because the Database Engine may raise errors with state 0, we recommend that you check the error state returned by ERROR_STATE before passing it as a value to the state parameter of RAISERROR.Example,BEGIN TRY
-- RAISERROR with severity 11-19 will cause execution to
-- jump to the CATCH block.
RAISERROR ('Error raised in TRY block.', -- Message text.
16, -- Severity.
1 -- State. );
END TRY
BEGIN CATCH
DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
DECLARE @ErrorState INT;
SELECT @ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE();
-- Use RAISERROR inside the CATCH block to return error
-- information about the original error that caused
-- execution to jump to the CATCH block.
RAISERROR (@ErrorMessage, -- Message text.
@ErrorSeverity, -- Severity.
@ErrorState -- State. );
END CATCH;
Vikas MishraPosted Jan 2, 2012, 11:34 AM