Monthly Archives: September 2015

How to execute the same SQL query on each database of a SQL Server instance ?

You want to execute the same SQL query on each database of your SQL Server. For example, because you have one database per customer and want to collect info about your customers’ databases version, size, etc.

The following T-SQL code illustrates how to get the number of tables in each database whose name starts with “RH”, and presents the result in one single recordset. Continue reading