标签:
在多个数据库同时执行同一个sql语句
--声明游标 declare name_cursor cursor scroll for select name from sys.databases where name not in (‘master‘,‘msdb‘,‘model‘,‘tempdb‘,‘ywmonitor‘) --打开游标 open name_cursor declare @dbname varchar(20) --移动游标 fetch next from name_cursor into @dbname while @@FETCH_STATUS =0 begin print @dbname exec sp_spaceused --查看数据库的空间使用情况 --grant showplan to [xxxx] --开通从库xxxx用户的查看语句的执行计划的权限 --exec sp_helpdb @dbname --查看数据库的信息 fetch next from name_cursor end --关闭游标 close name_cursor --释放游标 deallocate name_cursor
标签:
原文地址:http://www.cnblogs.com/lx823706/p/5546773.html