SQL Server
How to apply “try/catch” in query?
- SQL Server[sql]Begin try
BEGIN TRANSACTION;
DELETE___ WHERE___
End try
Begin catch
if @@error <> 0 goto err
else
begin
COMMIT TRANSACTION;
end
End catcherr:
ROLLBACK
[/sql]
How to get error message from “TRY.. CATCH..”
[sql]
BEGIN TRY
— Generate a divide-by-zero error.
SELECT 1/0;
END TRY
BEGIN CATCH
SELECT ERROR_MESSAGE() AS ErrorMessage;
END CATCH;
[/sql]
Leave a Reply