I want to read the schema information for each database
on the server to feed my data dictionary. I wrote the following :
USE master
DECLARE MyCursor CURSOR FOR select name from sysdatabases
DECLARE @mDB sysname(50)
OPEN MyCursor
FETCH NEXT FROM MyCursor INTO @mDB
WHILE @@FETCH_STATUS=0
BEGIN
USE @mDB
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
FETCH NEXT FROM MyCursor INTO @mDB
END
But an error message says "incorrect syntax" against the statement USE @mDB
Why ? can't I use avariable for the name of database !
Any comment will be much appriciated
on the server to feed my data dictionary. I wrote the following :
USE master
DECLARE MyCursor CURSOR FOR select name from sysdatabases
DECLARE @mDB sysname(50)
OPEN MyCursor
FETCH NEXT FROM MyCursor INTO @mDB
WHILE @@FETCH_STATUS=0
BEGIN
USE @mDB
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
FETCH NEXT FROM MyCursor INTO @mDB
END
But an error message says "incorrect syntax" against the statement USE @mDB
Why ? can't I use avariable for the name of database !
Any comment will be much appriciated