用友U8手工删除账套的SQL

DECLARE @AccID CHAR(3);
SET @AccID = '999';
--在此修改账套号
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; 

--账套数据库映射表
DELETE  FROM UA_AccountDatabase
WHERE   cAcc_Id = @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;
                IF @AccName = 'UFMeta_' + @AccID
                    BEGIN
                        EXECUTE sys.sp_detach_db @AccName;
                        PRINT '数据库' + @AccName + '已经分离';
                    END;
            END;
        FETCH NEXT FROM AccCur INTO @AccName;
    END;
CLOSE AccCur;
DEALLOCATE AccCur;
SELECT  '账套' + @AccID + '删除完成!';

你可能感兴趣的:(数据库,用友)