问题描述
declare @DB Varchar(20)declare dd_cursor cursor for select name from [master].[dbo].sysdatabases for read onlyopen dd_cursorfetch next from dd_cursor into @DBwhile @@fetch_status = 0beginprint @DBuse @DB --这句有错 是否有别的方法达到同样的效果,更改数据库更改到指定的数据库endclose dd_cursordeallocate dd_cursor
解决方案
declare @DB Varchar(20) declare @str varchar(30)declare dd_cursor cursor for select name from [master].[dbo].sysdatabases open dd_cursor fetch next from dd_cursor into @DB while @@fetch_status = 0 begin print @DB set @str= N'use ' + @DBexec (@str)fetch next from dd_cursor into @DBend close dd_cursor deallocate dd_cursor
时间: 2024-10-01 13:29:19