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

 

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

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语句

上一篇:方便john破解linux密码批处理


下一篇:linux上备份Oracle时EXP-00091的错误解决方法