码迷,mamicode.com
首页 > 数据库 > 详细

清理数据库事务——SQL语句

时间:2014-06-20 17:49:17      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:style   code   color   使用   strong   数据   

 

清除流程内部的所有相关数据

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 --等同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 --等同TOP(1) ;最关键是不能使用‘ROWCOUNT ‘在循环嵌套里面
select top(1) @caseCode=[caseCode] from @caseTemp

--删除,Add here
--DECLARE @applicationCode VARCHAR(50)

--SELECT @procedureCode=ProcedureCode FROM WorkFlowProcedure

--PRINT @procedureCode

--set @applicationCode = ‘20140613100462001‘

--SELECT @caseCode=CaseCode FROM WorkFlowCase WHERE ProcedureCode=@procedureCode AND ApplicationCode = @applicationCode

PRINT @caseCode + ‘ ‘ + @ProcedureCode

DELETE FROM [WorkFlowOpinion] WHERE ([CaseCode]=@caseCode)
DELETE FROM [WorkFlowCaseProperty] WHERE ([WorkFlowCaseCode]=@caseCode)
DELETE FROM [WorkFlowAct] WHERE ([CaseCode]=@caseCode)
DELETE FROM [WorkFlowActUser] WHERE ([CaseCode]=@caseCode)
DELETE FROM [WorkFlowCase] WHERE ([CaseCode]=@caseCode)

--SET ROWCOUNT 0
delete from @caseTemp where [caseCode] = @caseCode

end


--SET ROWCOUNT 0
delete from @procedureTemp where [ProcedureCode] = @ProcedureCode

--print ‘Name:----‘+@ProcedureCode
end

清理数据库事务——SQL语句,布布扣,bubuko.com

清理数据库事务——SQL语句

标签:style   code   color   使用   strong   数据   

原文地址:http://www.cnblogs.com/guanshan/p/guan111.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!