How to Merge tables of two databases one in sql server 2000 & second is in sql server 2005.

  • Anybody can tell me the right procedure to merge two database of same design & structure,one database is in sql server 2000 & second database is in sql server 2005. the matter is urgent, i will be very thankfull for this help.

  • Can you give us more information what do you want to do (to synhronize data in one db comparing with other, or make union of data,...)?

  • Please let us know what do you mean by Merge. Are you looking at merging data? Since you specified that the structure is same. You may want to run a DTS package for import/export data. However it would be more relevant to answer if you can post the exact requirement.

    Prasad Bhogadi
    www.inforaise.com

  • actually my some old data is persist in old server ie- in sql server 2000, so i have to migrate & merge that in my new database, the structures of both the database is same. should i do it by DTS Package or By query, please explain me in detail, because i never did this.

    Thanks

  • You should be really careful in structuring the insert queries as to which one needs to be executed first and what is next based on the dependencies (Relationships) defined on the tables. If you have master and child tables in your database, since you may want to write a stored procedure that inserts the records into master table, fetches the identity or new primary key of master table and runs the inserts on the child table with reference to this parent table. What is the volume of tables and data in your database?

    Prasad Bhogadi
    www.inforaise.com

  • Red gate SQL Data Compare tool is good option for what you need.

    Otherwise you can use DTS/SSIS or to create your own script.

    Which way to use depend on your time and how often you are going to execute this procedure (once, occasionally or on regular basis).

  • If you are going to make a script than you'd write T-SQL commands for every table like this:

    -- Server2 is the other server linked on Server1 with proper security

    -- table1 on Server1 is going to be synhronized with table1 on Server2

    UPDATE (table1)

    SET

    (column1) = (alias).(column1),

    (column2) = (alias).(column2),

    ...

    (columnN) = (alias).(columnN),

    FROM (table1)

    INNER JOIN (Server2).(db).(owner).(table1) (alias) ON

    (table1).(PK_column1) = (alias).(PK_column1)

    and (table1).(PK_column2) = (alias).(PK_column2)

    ...

    and (table1).(PK_columnN) = (alias).(PK_columnN)

    INSERT INTO (table1) ((column1), (column2), ..., (columnN))

    SELECT (alias).(column1), (alias).(column2), ..., (alias).(columnN)

    FROM (table1)

    RIGHT JOIN (Server2).(db).(owner).(table1) (alias) ON

    (table1).(PK_column1) = (alias).(PK_column1)

    and (table1).(PK_column2) = (alias).(PK_column2)

    ...

    and (table1).(PK_columnN) = (alias).(PK_columnN)

    WHERE (table1).(PK_column1) Is Null

    DELETE FROM (table1)

    LEFT JOIN (Server2).(db).(owner).(table1) (alias) ON

    (table1).(PK_column1) = (alias).(PK_column1)

    and (table1).(PK_column2) = (alias).(PK_column2)

    ...

    and (table1).(PK_columnN) = (alias).(PK_columnN)

    WHERE (alias).(PK_column1) Is Null

    As Prasad said you'd take care about referential integrity so you will execute insert and update statement first going from top tables (parents) to bottom (child). When this is done then you can delete data in reverse order from bottom to top.

  • Thanks to Nebojsa Ilic & all friends who guided me, I will try it Trough DTS or with sql script, i think now it will be achieved. Thanks again

    Raj

  • One other suggestion, I'd use SSIS over DTS especially since you're trying to move data to 2005.

    "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

Viewing 9 posts - 1 through 8 (of 8 total)

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