我正在尝试获取我的服务器上的数据库列表,其数据库包含表“Foobar”。我遇到的障碍是我无法弄清楚如何将@CurrDB 与INFORMATION_SCHEMA 结合使用。有什么建议么?
DECLARE @CurrDB varchar(255)
DECLARE RecSet CURSOR FOR
Select [name] FROM master..sysdatabases
OPEN RecSet
Fetch NEXT FROM RecSet Into @CurrDB
WHILE (@@FETCH_STATUS = 0)
BEGIN
Fetch NEXT FROM RecSet Into @CurrDB
IF (EXISTS (SELECT * FROM @CurrDB..INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Foobar'))
BEGIN
print @CurrDB
--do other stuff
END
END
Close RecSet
DEALLOCATE RecSet