SQL stored procedure transaction writing.

Source: Internet
Author: User

Set ansi_nulls on
Go
Set quoted_identifier on
Go
-- ===================================================== ======
-- Author: <author, Name>
-- Create Date: <create date,>
-- Description: <description,>
-- ===================================================== ======
Create procedure <procedure_name, sysname, procedurename>
-- Add the parameters for the stored procedure here
<@ Param1, sysname, @ P1> <datatype_for_param1, int >=< default_value_for_param1, 0>,
<@ Param2, sysname, @ P2> <datatype_for_param2, int >=< default_value_for_param2, 0>
As
Begin

The Set xact_abort ON--SQL statement produces a runtime error and the entire transaction is terminated and rolled back

Begin tran -- start the transaction here

-- Set nocount on added to prevent extra result sets from
-- Interfering with select statements.
Set nocount on;

-- Insert statements for procedure here
Select <@ param1, sysname, @ P1>, <@ param2, sysname, @ P2>

Commit tran -- if no error occurs, submit the transaction directly.
End
Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.