Given a multi-tenant setup with one database that holds the tenant data, and one database for each tenant, how can you construct a query to look up the same piece of data in each tenant database?
eg The tenant master database has a table called Tenants:
[TenantMaster].[dbo].[Tenants]
Id, Name, DatabaseName
1, Bob, bobs_db_name
2, Kate, kates_db_name
And each individual tenant has a table called Widgets:
[bobs_db_name].[dbo].[Widgets]
Id, Name
1, Red widget
Is it possible to write a select query to get the count of widgets in each tenant DB? Or does it require a cursor or a store procedure? eg the output would be:
Tenant, WidgetCount
Bob, 10
Kate, 12