求助,利用查询分析器如何快速批量分离数据库
我有几百个数据库,想分离指定年份的数据库,请问如何操作?
库名形如:
...
DATA_099_2012
DATA_101_2011
DATA_101_2012
DATA_102_2010
DATA_102_2011
DATA_102_2012
DATA_103_2011
DATA_103_2012
DATA_104_2012
...
...
------解决方案--------------------
--sql 2005
use master
declare @dbname as varchar(50)
while exists(select 1 from sys.databases where name like 'data_%')
begin
set @dbname = (select top 1 name from sys.databases where name like 'data_%')
exec sp_detach_db @dbname, 'false'
end