問題現(xiàn)象:如何用語句快速刪除用友U8ERP軟件中的帳套  ?因升級帳套太多,手工刪除太慢

解決方案: 提供語句解決:

DECLARE @AccID char(3)

SET @AccId = '112'--在此修改賬套號

USE UFSYSTEM

DELETE FROM UA_BackupLog WHERE cAcc_Id=@AccId

DELETE FROM UA_BackupPlans WHERE cAcc_Id=@AccId

DELETE FROM UA_BackupPlan WHERE cPlan_Id not in (select cPlan_Id FROM UA_BackupPlans)

DELETE FROM UA_HoldAuth WHERE cAcc_Id=@AccId

DELETE FROM UA_Auth WHERE cAcc_Id=@AccId

DELETE FROM UA_FlowItems WHERE cAccId=@AccId

DELETE FROM UA_FlowLines WHERE cAccId=@AccId

DELETE FROM UA_Identity WHERE cAcc_Id=@AccId

DELETE FROM UA_Account_sub WHERE cAcc_Id=@AccId

DELETE FROM UA_Log WHERE cAcc_Id=@AccId

DELETE FROM UA_Period WHERE cAcc_Id=@AccId

DELETE FROM UA_Account WHERE cAcc_Id=@AccId

DELETE FROM UA_Message WHERE Account=@AccId

DELETE GDP_JccpConfigure WHERE UF_DB_NAME=@AccId

USE master

DECLARE AccCur CURSOR

FOR SELECT NAME FROM sysdatabases

DECLARE @AccName varchar(40)

OPEN AccCur

FETCH NEXT FROM AccCur INTO @AccName

WHILE (@@fetch_status <>; -1)

BEGIN

IF (@@fetch_status <>; -2)

BEGIN

IF (left(@AccName,10)='UFDATA_' + @AccId) and len(@AccName)=15

BEGIN

EXECUTE sp_detach_db @AccName

--PRINT '賬套庫'+@AccName + '已分離!'

END

END

FETCH NEXT FROM AccCur INTO @AccName

END

CLOSE AccCur

DEALLOCATE AccCur

SELECT '賬套'+@AccId+'刪除完成!'