Stored procedure example, with input and output parameters, with rollback

Source: Internet
Author: User
Tags stored procedure example

To create the code:

Create procedureProc_delete_business_and_workflow_data_by_business_key (--Input Parameters    @bkey varchar( -),    --Output Parameters    @error intoutput) as--Start a transactionbegin Transaction--Business OperationsDelete  fromT_jcwherejc_id=@bkeyDelete  fromT_zgwherezg_id=@bkeyDelete  fromT_jkfwherejkf_id=@bkeyDelete  fromT_wxzywhereWxzyid=@bkeyDelete  fromT_sgzwhereId=@bkeyDelete  fromT_sgz_recheckwhereId=@bkeyDelete  fromT_workreportwhereId=@bkeyDelete  fromT_report_setdatewhereId=@bkeyPrint(Char(Ten)+'Business Data operation completed')--get error code, @ @ERROR as system parameterSet @error=@ @ERRORPrint('Error code:'+Convert(varchar( -),@error))if(@error=0)    begin    --Commit a transaction    Commit Transaction    Print('COMMIT TRANSACTION operation was performed')    EndElse    begin    --rolling back    rollback Transaction; Print('a ROLLBACK TRANSACTION operation was performed'); End

Calling code:

--define variables to receive stored procedure output valuesDeclare @error  int --call the stored procedure, the parameters are separated by a space directly following the stored procedure name, and the parameters are separated by commas, and the output parameter is followed by a keywordexecProc_delete_business_and_workflow_data_by_business_key' -',@errorOutput--outputs the stored procedure output values obtained to verify that the execution is normalPrint('error code returned by the stored procedure:'+Convert(varchar( -),@error))

Stored procedure example, with input and output parameters, with rollback

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.