Saturday, August 8, 2009

Compare SQL Databases

If you ever come across a situation where your application behaves differently with different DBs you have and not sure if any of the Stored procedures have changed...?
Following SQL script can be used to compare the Stored procedures.
select top SYSCOM_1.text, DB2.text 
from MyDATABASE_1.dbo.syscomments SYSCOM_1 
inner join 
sysobjects so on so.id=SYSCOM_1.id inner join 
(select SYSCOM_2.text,SYSCOM_2.id, so.name from MyDATABASE_2.dbo.syscomments SYSCOM_2inner join MyDATABASE_2.dbo.sysobjects so on so.id=SYSCOM_1.id )
DB2 on so.name = DB2.name COLLATE DATABASE_DEFAULT 
where DB2.text <> SYSCOM_1.text COLLATE DATABASE_DEFAULT

No comments: