批量分离SQL数据库语句

--sp_helpdb--查看可用数据库 
declare @name sysname, @sql nvarchar(4000)
DECLARE roy CURSOR 
FOR 
--排除不分离的数据库名就行了
SELECT name FROM sysdatabases where name not in ('master','tempdb','pubs','Northwind','msdb','model')
open roy
FETCH NEXT FROM roy INTO @name
WHILE @@FETCH_STATUS = 0
	begin
		set @sql=N'
		EXEC sp_detach_db '+ @name+', '+ 'true'
		EXEC(@sql)
		print @name
		FETCH NEXT FROM roy INTO @name
	end
CLOSE roy
DEALLOCATE roy

 

转载于:https://www.cnblogs.com/jsonzheng/p/3637721.html

你可能感兴趣的:(批量分离SQL数据库语句)