I am not an expert on SQl Server. Is this a valid pattern for handling errors in a batch of SELECT, INSERT…in SQl SERVER ? (I use v.2008)
BEGIN TRANSACTION
BEGIN TRY
-- statement 1
-- statement 2
-- statement 3
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
END CATCH
Thanks
I use something like this:
Since you are just doing a batch of
a batch of SELECT, INSERT, you can just remove the CREATE PROCEDURE and parameter declarations and have the first line start at BEGIN TRY. Also, because you are not creating a procedure, replace any RETURN statements withGOTO TheEndand add aTheEnd:label at the script’s bottom.