清除流程内部的所有相关数据
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 [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
清理数据库事务——SQL语句