How can I compare tables in two different databases using SQL?

Posted by chama on Stack Overflow See other posts from Stack Overflow or by chama
Published on 2011-03-10T16:06:10Z Indexed on 2011/03/10 16:10 UTC
Read the original article Hit count: 247

Filed under:
|

I'm trying to compare the schemas of two tables that exist in different databases. So far, I have this query

SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('table1')

The only thing is that I don't know how to use the sys.columns to reference a database other than the one that the query is connected to. I tried this

SELECT * FROM db.sys.columns WHERE object_id = OBJECT_ID('table1')

but it didn't find anything.

I'm using SQL Server 2005

Any suggestions? thanks!

© Stack Overflow or respective owner

Related posts about sql-server-2005

Related posts about tsql