How to find common tables between two databases?

  • Hello All,

    Can someone tell me how can we find common tables between 2 databases? Any scripts or querry plzz.

    thanks in advance...

  • sqlpanther (4/10/2013)


    Hello All,

    Can someone tell me how can we find common tables between 2 databases? Any scripts or querry plzz.

    thanks in advance...

    common table , by name , by attributes or by data ?

    ~ demonfox
    ___________________________________________________________________
    Wondering what I would do next , when I am done with this one :ermm:

  • Yes with common tables, attibutes..no need for data..

  • if it just for a quick look - you could query sys.objects / sys.columns / sys.tables for what you want, then run the same query over linked server and put it into a temp table and do your analysis from there

  • Are the databases on the same server?

  • here's a really easy example:

    --common tables between the two

    SELECT name from SandBox.sys.tables

    INTERSECT

    SELECT name from Dictionary.sys.tables

    --tables only in SandBox

    SELECT name from SandBox.sys.tables

    EXCEPT

    SELECT name from Dictionary.sys.tables

    --tables only in Dictionary

    SELECT name from Dictionary.sys.tables

    EXCEPT

    SELECT name from SandBox.sys.tables

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Yes all the objects are in the same server

  • sqlpanther (4/10/2013)


    Yes all the objects are in the same server

    Then you can do as Lowell suggests...or something similar with sys.columns if you need to drill down further.

  • Lowell (4/10/2013)


    here's a really easy example:

    --common tables between the two

    SELECT name from SandBox.sys.tables

    INTERSECT

    SELECT name from Dictionary.sys.tables

    --tables only in SandBox

    SELECT name from SandBox.sys.tables

    EXCEPT

    SELECT name from Dictionary.sys.tables

    --tables only in Dictionary

    SELECT name from Dictionary.sys.tables

    EXCEPT

    SELECT name from SandBox.sys.tables

    Apart from that , you need to check the database.sys.all_columns for attributes comparison....

    ~ demonfox
    ___________________________________________________________________
    Wondering what I would do next , when I am done with this one :ermm:

  • Thanks SSchap...and all you ...it was quite quite simple...

Viewing 11 posts - 1 through 10 (of 10 total)

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