Say I have the following databases in SQL Server 2008 R2
db1, db2, db3, db4, db5......dbn
each database has a table A
which contains the columns C1,C2,C3
I can write the following Select
statement on two databases to get the data across them:
Select C1,C2,C3
FROM db1.dbo.A
UNION ALL
Select C1,C2,C3
FROM db2.dbo.A
However if I have 50 databases on the same server I don't want to write a UNION ALL
for each.
Can someone give me a script to do this? I can modify the script to exclude system databases myself.
Thanks