SQL Server RAISERROR
SQL Server RAISERROR is a SQL statement in the SQL Server Specific category. SQL Server: generates an error message with severity level and state. Can be used for custom validation. The syntax is RAISERROR (N'message', severity, state);. It returns error raised. A typical example: CREATE PROCEDURE UpdateSalary(@emp_id INT, @new_salary DECIMAL) AS BEGIN IF @new_salary < 0 BEGIN RAISERROR(N'Salary cannot be negative: %d', 16, 1, @new_salary); RETURN; END IF @new_salary > 1000000 RAISERROR(N'Salary exceeds maximum: %d', 16, 1, @new_salary); UPDATE employees SET salary = @new_salary WHERE id = @emp_id; END; -- Severity levels: -- 10: informational -- 11-16: user errors -- 17-19: resource errors -- 20-25: fatal errors A close relative is OUTPUT Clause, which sQL Server: returns values from DML statements (like PostgreSQL RETURNING). A close relative is STUFF(), which sQL Server: deletes a specified length of characters from a string and inserts another string at the start position.