I have many databases (more than 50) on SQL Server. All databases are identical. Each database has a table named DBVersion. Each DBVersion has a column: “Version” which is of type varchar. In this table, always one record exists.
How can I loop through all the databases, select the “Version” from the table DBVersion and print in Microsft SQL Server Management studio the results?
The result should look like:
- Database1 – Version: 5
- Database2 – Version: 8
- Database50 – Version: 6
Thanks in advance.
You can use sp_msforeachdb to itereate databases if they are on the same instance of SQL-Server
There is some sceptisism about using undocumented procedures, so you could rewrite this with a cursor: