删除年度数据:
select tname ,name
From (SELECT object_name([id]) as tname,name From [syscolumns]
where [name] in('cacc_id' ,'accid','caccid') and object_name([id])<>'UA_Account'
and objectproperty([id],'isusertable')=1)
as t Left Join (SELECT distinct object_name([rkeyid]) as rname
FROM [sysreferences]) as r on tname=rname Left Join
(SELECT distinct object_name([fkeyid]) fname
FROM [sysreferences]) as f
on fname=tname order by tname ,[name]
select tname ,name
From (SELECT object_name([id]) as tname,name From [syscolumns]
where [name] like '%year' and object_name([id])<>'UA_Account'
and objectproperty([id],'isusertable')=1)
as t Left Join (SELECT distinct object_name([rkeyid]) as rname
FROM [sysreferences]) as r on tname=rname Left Join
(SELECT distinct object_name([fkeyid]) fname
FROM [sysreferences]) as f
on fname=tname order by tname ,[name]
delete from UA_Account_sub where cAcc_Id=901
and iYear=2010
delete from UA_BackupLog where cAcc_Id=901
and iYear=2010
delete from UA_BackupPlans where cAcc_Id=901
and iYear=2010
delete from UA_HoldAuth where cAcc_Id=901
and iYear=2010
delete from UA_Log where cAcc_Id=901
and iyear=2010
delete from UA_Period where cAcc_Id=901
and iYear=2010
delete from UA_Task where cAcc_Id=901
and iYear=2010
Drop database ufdata_901_2010
删除帐套
select tname ,name From (SELECT object_name([id]) as tname,name From [syscolumns] where [name] in('cacc_id' ,'accid','caccid') and object_name([id]) not in('UA_Account') ) as t Left Join (SELECT distinct object_name([rkeyid]) as rname FROM [sysreferences]) as r on tname=rname Left Join (SELECT distinct object_name([fkeyid]) fname FROM [sysreferences]) as f on fname=tname order by fname desc, rnameselect tname ,name From (SELECT object_name([id]) as tname,name From [syscolumns] where [name] in('cacc_id' ,'accid','caccid') and object_name([id]) not in('UA_Account') ) as t Left Join (SELECT distinct object_name([rkeyid]) as rname FROM [sysreferences]) as r on tname=rname Left Join (SELECT distinct object_name([fkeyid]) fname FROM [sysreferences]) as f on fname=tname order by fname desc, rname
delete from UA_Task where cAcc_Id=999
delete from UA_Period where cAcc_Id=999
delete from UA_Log where cAcc_Id=999
delete from UA_HoldAuth where cAcc_Id=999
delete from UA_Account_sub where cAcc_Id=999
delete from UA_BackupLog where cAcc_Id=999
delete from UA_BackupPlans where cAcc_Id=999
DELETE FROM UA_account WHERE cacc_id = '999'
Drop database ufdata_999_2008