@@Error and Raiseerror

Define @@Error and raiseerror.

Raiseerror is used to produce an error which is user defined or used to invoke an existing error present in sys.messages. They are most commonly used in procedures when any condition fails to meet.

Example:
SELECT COUNT(*) INTO :rows FROM student
WHERE studentid = : studentid;

IF :rows <> 0 THEN
RAISE ERROR 1 MESSAGE 'Student id exists in the "Student" table.';
ENDIF;


@@error is used to hold the number of an error. When a T-SQL statement is executed, @@error value is set to 0 by the SQL server. If an error occurs, the number of that error is assigned as a value.

Example: the value of @@error can be checked for “0” value to be safe.

Define @@Error and raiseerror.

@@Error
- It is system variable that returns error code of the SQL statement.
- If no error, it returns zero.
- @@Error is reset after each SQL statement.

Raiseerror
Raiseerror command reports error to client application.

Define @@Error and raiseerror.

SQL Server provides @@Error variable that depicts the status of the last completed statement in a given set of statements. If the statement was executed successfully the variable holds 0 value else it holds the number of the error message that occurred. Raiseerror is used to send messages to applications using the same format as a system error or warning generated by SQL Server engine. It can also return a user defined message. RAISEERROR is often used to help in troubleshooting, check values of data, returns variable value based messages, cause an execution to jump to a CATCH from TRY.
SQL Server Database Architecture
SQL Server Database Architecture - Here we have tried to cover all about SQL Server Database Architecture such as logical component and physical component
Normalization and Denormalization
Define Normalization and De- Normalization. We have answered to this question in this section....
Transact SQL - DDL,DCL,DML
Types of Transact-SQL - SQL Server Provides three types of Transact-SQL statements namely DDL, DCL, and DML. Data Definition Language (DDL). It allows creating, altering and dropping database objects........
Post your comment