Cleanup database Transaction--sql statement

Source: Internet
Author: User
Tags rowcount

Clears all relevant data within the process

EG1:

DECLARE @procedureTemp table
(
[Procedurecode] varchar (10)
)
DECLARE @ProcedureCode varchar (10)

INSERT into @procedureTemp SELECT Procedurecode from Workflowprocedure

While EXISTS (select [Procedurecode] from @procedureTemp)
Begin
--set ROWCOUNT 1--equivalent top (1)
Select Top (1) @ProcedureCode =[procedurecode] from @procedureTemp

DECLARE @caseTemp table
(
[Casecode] varchar (10)
)
DECLARE @caseCode varchar (10)

INSERT into @caseTemp SELECT casecode from workflowcase WHERE procedurecode = @ProcedureCode

While EXISTS (select [Casecode] from @caseTemp)
Begin
--SET ROWCOUNT 1--equals top (1); The key is not to use ' ROWCOUNT ' inside the loop nesting
Select Top (1) @caseCode =[casecode] from @caseTemp

--Delete, Add here
--declare @applicationCode VARCHAR (50)

--select @procedureCode =procedurecode from Workflowprocedure

--print @procedureCode

--set @applicationCode = ' 20140613100462001 '

--select @caseCode =casecode from workflowcase WHERE [email protected] and Applicationcode = @applicationCode

PRINT @caseCode + ' + @ProcedureCode

DELETE from [workflowopinion] WHERE ([casecode][email protected])
DELETE from [Workflowcaseproperty] WHERE ([workflowcasecode][email protected])
DELETE from [Workflowact] WHERE ([casecode][email protected])
DELETE from [Workflowactuser] WHERE ([casecode][email protected])
DELETE from [Workflowcase] WHERE ([casecode][email protected])

--set ROWCOUNT 0
Delete from @caseTemp where [casecode] = @caseCode

End


--set ROWCOUNT 0
Delete from @procedureTemp where [procedurecode] = @ProcedureCode

--print ' Name:----' [email protected]
End

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.