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