다음을 통해 공유


Running a SQL Statement on all Databases

 exec sp_MsForEachDB 'SELECT "?", 1'

The ? will be replaced by the current database name. To run a query that references a table, you need to make sure that the table exists first, as this query will run on system databases as well.