I am trying to run a SQL Server export which compares the table names listed in three or more databases on a SQL Server instance (actually the number is a lot higher!)
I can use something simple like the following to get a list of all of the tables in a particular database.
SELECT [name]
FROM DB1.sys.tables
What I would like to be able to do is to be able to join these for multiple databases to create a single view to spot differences (and similarities).
So for example if I have three databases with the following tables
DB1:
Customers
Orders
Products
DB2:
Products
Orders
DB3:
Products
Suppliers
How could I join them all together to get something like the following?
| DB1 | DB2 | DB3 |
|---|---|---|
| Customers | NULL | NULL |
| Orders | Orders | NULL |
| Products | Products | Products |
| NULL | NULL | Suppliers |
Thanks!