SQL 批量删除Database

use master
declare @sql varchar(max)
declare @databasename varchar(max)

while exists(select name from sysdatabases where dbid>4)
begin
select top 1 @databasename=name from sysdatabases where dbid>4

if exists(select * from sysdatabases where dbid>4)
begin
print 'dropping database: '+@databasename
select @sql=+'DROP DATABASE ' + name + '; ' from sysdatabases where dbid>4;
exec (@sql)
end
end

posted @ 2016-05-25 15:27  Apple Zhang  阅读(287)  评论(0编辑  收藏  举报