所以,执行下列代码就能实现你的需求:use master go declare @sql nvarchar(max)select @sql=isnull(@sql,'')+'drop database '+name+' no wait;' from sys.databases where owner_sid<>0x01exec(@sql)注:后果自负
orphan user,可以dropselect * from sys.database_principals a where not exists (
select 1 from sys.server_principals b where a.sid = b.sid ) and a.type in ('S','U','G') and a.name not in ('guest', 'INFORMATION_SCHEMA', 'sys', 'BROKER_USER', 'dbo')
go
declare @sql nvarchar(max)select @sql=isnull(@sql,'')+'drop database '+name+' no wait;' from sys.databases where owner_sid<>0x01exec(@sql)注:后果自负
where not exists
(
select 1 from sys.server_principals b
where a.sid = b.sid
)
and a.type in ('S','U','G')
and a.name not in ('guest', 'INFORMATION_SCHEMA', 'sys', 'BROKER_USER', 'dbo')
1.比如系统只要查询当年内的数据,那么去年及更早的数据就是垃圾数据。
2.系统升级或改造后,某些功能被去除,部分相关的表可能永远也不会再用到,那么那些表的数据可以算垃圾数据。
3.错误的数据,比如不小心插入的错误数据,或者BUG导致错误数据,这些数据通常都是垃圾数据。
4.缓存表的数据,某些表只是作为增加性能额外添加的(例如先同步到缓存表再作二次处理的情况),这些缓存表通常都是一次性用途,用完之后,就变成垃圾数据。
5.辅助表的数据,有时为了开发或测试方便添加的一些跟业务无关的表,这些表的数据可以算是垃圾数据。PS:即使是垃圾数据,也不排除有利用的一天。