Consulting

Results 1 to 4 of 4

Thread: SQL Compare Databases

  1. #1
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location

    SQL Compare Databases

    Does anyone know a SQL Server script to compare one database with another?.

    So, compare DB1 against DB2 and list what table exists in DB1 but not DB2?

    Thanks,

  2. #2
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    The only way I can think to do this is via VBA- using connections to pull out table lists into recordsets and then comparing them. If you'd like some example code for this, let me know- I'll have to dig it up.
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  3. #3
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Hi Randy,

    If you could find the code, great :-)
    I've been looking at Microsoft Stored Procedures sp_helpdb etc...

  4. #4
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    This code will allow you to create a list of tables in a database. You'll need to set a reference to Microsoft ADO ext 2.8 for DDL and Security (your version number may be different). You'll also need to change the code so it puts the values into a recordset, instead of displaying them in the Immediate window:
    [VBA]Dim cat As ADOX.Catalog
    Dim tbl As ADOX.Table

    Set cat = New ADOX.Catalog
    cat.ActiveConnection = 'enter the connection string for your database here

    'loop through all tables and display info
    For Each tbl In cat.Tables
    If tbl.Type <> "VIEW" AND tbl.Type <> "SYSTEM TABLE" AND _
    tbl.Type <> "ACCESS TABLE" Then Debug.Print tbl.Name
    Next tbl

    'cleanup
    set cat = Nothing
    MsgBox "Data Gathered: View Immediate Window for tables list."[/VBA]

    In Theory, you would need to populate 2 different recordsets, one for each database, then you just need to compare the recordsets.

    HTH
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •