MSSQL删除数据库脚本
Tags: DROP DATABASESQL SERVER删除数据库
若数据库较多时,可以使用如下脚本生成命令来删除数据库:
1 2 3 4 5 6 7 8 9 10 11 12 | select a.spid ,status ,loginame ,db_name(dbid) db_name , cpu ,a.physical_io,convert(varchar(20),a.login_time,120) login_time,convert(varchar(20),a.last_batch,120) last_batch, a.hostname as hostname,a.cmd as cmd,blocked as blocked,'kill '+ CAST(spid AS VARCHAR)+' ;' kill_process from sys.sysprocesses a where db_name(dbid) not in ('master','model','msdb','tempdb','ReportServer','ReportServerTempDB') order by a.status; SELECT 'drop database ['+name+'];' FROM sys.databases where name not in ('master','model','msdb','tempdb','ReportServer','ReportServerTempDB') and state=0 ORDER BY Name; |