I need to compare tables on two sql databases for differences with one customer

  • I need to compare tables on two sql databases for differences with one customer

    the first problem is

    I am not sure how to select two diffrent datebase with the tsql in a select statement?

  • To select from another database use a fully qualified name Database.Owner.Table as long as it resides on the same server and your account has access. If its on another server then setup a linked server.

    So basically something like

    [Code]

    select *

    from db1.dbo.table

    [/code]

    Then you cna use inner and outter joins to query and see differences.

  • You could try 3rd party products like Red Gate's SQL Compare or Apex SQLDiff. Both have trial periods available for you to test them out in your environment.

    Disclaimer - I work for Red Gate 🙂

    Rachel.

  • Do you mean compare the data or compare the structures?

    Rachel is right, Red Gate & Apex both offer great tools for doing either of these operations. I prefer the Red Gate tools and I don't work for them.

    However, with work, you can do this yourself. Here's an example that compares structures between two databases using TSQL code: http://www.sqlservercentral.com/scripts/T-SQL+Aids/30564/[/url]

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • twdavis (10/20/2008)


    I need to compare tables on two sql databases for differences with one customer

    the first problem is

    I am not sure how to select two diffrent datebase with the tsql in a select statement?

    This link is helpful for you

    http://www.sqlservercentral.com/scripts/T-SQL+Aids/31844/

    this link demonstrates the comparison of the two tables in the same database. but if you want to use table(s) in different databases then you will have to link both the Servers and then by prefixing the name of the server before the database table, you can perform the above comparison

    kshitij kumar
    kshitij@krayknot.com
    www.krayknot.com

  • The 3rd software is the first select

  • What kind of comparison?

    Will this help?

    Good luck

    -- CK

  • I have 3 sql servers DEV, TEST, Production I would like to compare about fifty customer tables between TEST and Production. I just want to see what the difference between the two are. Reason I have a few customers that when they came over from test to the production server they did not come over correctly because they do not function correctly. I would like to see only what has changed from TEST to Production. I may also need this for Products. I would like this in a query for future use.

  • I used ApexSQLDiff to do this and it worked great. The DIFF script is fairly verbose

    but you can modify it at your desire.

  • If you want to see the differences in the content of two tables, you can try this

    Select * from table1

    except

    Select * from table2

    Both tables must have the same structure

  • Thank you that works perfect.

  • Is there a wild card to use for the cust_table name. something like cust_% ?

    SELECT * HMDEV.dbo.cust_table

    except

    SELECT * HMTST.dbo.cust_table

  • is there away to mark the rows with the table name that is different?

  • I must admit for either schema or data compares between databases I always go for the redgate suite..

  • I work for Red Gate, so you know. I'll say that there's no way you could write anything that works as well or reliably as their compare products in anywhere near a reasonable amount of time. If you have finding yourself comparing tables or schemas often and trying to alter scripts, you're really being inefficient.

    That being said, I never used their products when I was a DBA, but I also knew me schemas inside and out and had very tight, perhaps too tight, control over things. As I look back, I realize that I should have investigated them a bit to see if they would help me.

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic. Login to reply