Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Programming / SQL / July 2008

Tip: Looking for answers? Try searching our database.

Schema comparison of two databases

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Omid Golban - 17 Jul 2008 17:33 GMT
Visual Studio database edition's schema comparison tool does a good job of
identifying all differences between two databases.

How do I go about doing this schema comparison directly in SQL server 2005
or 2008 and without the Visual Studio database edition?

Thank you,
Omid
Stuart Ainsworth - 17 Jul 2008 17:52 GMT
On Jul 17, 12:33 pm, Omid Golban
<OmidGol...@discussions.microsoft.com> wrote:
> Visual Studio database edition's schema comparison tool does a good job of
> identifying all differences between two databases.
[quoted text clipped - 4 lines]
> Thank you,
> Omid

Management Studio doesn't have that capability built in; there are
several third party tools available. I use RedGate's SQL Compare, but
I believe Apex makes one as well.
Denny Cherry - 17 Jul 2008 18:36 GMT
As does Quest Software.
(http://www.quest.com/Change-Director-for-SQL-Server/)

There's a link for a free trial (and a little video I did for them on
the bottom of the page).

Denny

>On Jul 17, 12:33 pm, Omid Golban
><OmidGol...@discussions.microsoft.com> wrote:
[quoted text clipped - 10 lines]
>several third party tools available. I use RedGate's SQL Compare, but
>I believe Apex makes one as well.
Eric Russell - 17 Jul 2008 18:31 GMT
You can script the databases out to seperate folders (one script per object),
and then use WinDiff (free) or Beyond Compare (~$30) to highlight
differences. If you want to pay for it, Red Gate SQL Compare is better,
doesn't require manual scripting, and can also create scripts to deploy
differences.

> Visual Studio database edition's schema comparison tool does a good job of
> identifying all differences between two databases.
[quoted text clipped - 4 lines]
> Thank you,
> Omid
Bob - 17 Jul 2008 20:49 GMT
It is possible to do comparisons as queries.  The only limit is your
imagination!  And it's free.

Some examples:

-- Objects in db1 not in db2
SELECT name
FROM db1.sys.objects
WHERE is_ms_shipped = 0
EXCEPT
SELECT name
FROM db2.sys.objects
WHERE is_ms_shipped = 0

-- Objects in db2 not in db1
SELECT name
FROM db2.sys.objects
WHERE is_ms_shipped = 0
EXCEPT
SELECT name
FROM db1.sys.objects
WHERE is_ms_shipped = 0

-- Tables where columns or data-types are different
SELECT OBJECT_NAME( object_id, DB_ID( 'db1' ) ), name, TYPE_NAME(
user_type_id ), max_length, precision, scale, is_nullable
FROM db1.sys.columns
EXCEPT
SELECT OBJECT_NAME( object_id, DB_ID( 'db1' ) ), name, TYPE_NAME(
user_type_id ), max_length, precision, scale, is_nullable
FROM db2.sys.columns

-- Vice versa
SELECT OBJECT_NAME( object_id, DB_ID( 'db1' ) ), name, TYPE_NAME(
user_type_id ), max_length, precision, scale, is_nullable
FROM db2.sys.columns
EXCEPT
SELECT OBJECT_NAME( object_id, DB_ID( 'db1' ) ), name, TYPE_NAME(
user_type_id ), max_length, precision, scale, is_nullable
FROM db1.sys.columns

USE db1
-- Be careful using OBJECT_SCHEMA_NAME and OBJECT_NAME, which should be
called in relevant database, or pass in DB_ID argument,
-- eg SELECT OBJECT_NAME( object_id, DB_ID( 'db1' ) )
-- Objects with text ( ie stored procs, views, triggers etc ) exist in both
databases or text is different
SELECT DB_NAME() AS database_name, OBJECT_SCHEMA_NAME( object_id ) AS
schema_name, OBJECT_NAME( object_id ) AS object_name, CHECKSUM( definition )
AS object_checksum
INTO #sql_modules
FROM sys.sql_modules
GO

USE db2

INSERT INTO #sql_modules
SELECT DB_NAME() AS database_name, OBJECT_SCHEMA_NAME( object_id ) AS
schema_name, OBJECT_NAME( object_id ) AS object_name, CHECKSUM( definition )
AS object_checksum
FROM sys.sql_modules
GO

-- Query the differences

SELECT schema_name, object_name, object_checksum
FROM #sql_modules
WHERE database_name = 'db1'
EXCEPT
SELECT schema_name, object_name, object_checksum
FROM #sql_modules
WHERE database_name = 'db2'

SELECT schema_name, object_name, object_checksum
FROM #sql_modules
WHERE database_name = 'db2'
EXCEPT
SELECT schema_name, object_name, object_checksum
FROM #sql_modules
WHERE database_name = 'db1'

HTH
wBob
Alex Kuznetsov - 17 Jul 2008 21:42 GMT
On Jul 17, 11:33 am, Omid Golban
<OmidGol...@discussions.microsoft.com> wrote:
> Visual Studio database edition's schema comparison tool does a good job of
> identifying all differences between two databases.
[quoted text clipped - 4 lines]
> Thank you,
> Omid

Using a tool is typically much cheaper.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.