We have two databases, almost identical, and we are trying to copy data from Table1 in Database1 to Table1 in Database2.
DB1..TBL1 has these columns:
Col1: primary key integer
Col2: text
Col3: Identity column
DB2..TBL1 has the same structure, and ALSO already has data in it, that we want to preserve.
We want to INSERT in DB2 those rows from DB1 that are not already in DB2.
The problem is that we can't just insert all the rows and columns from DB1 into DB2 since DB2 has Col1 already populated, and we can't overwrite those.
Basically, we need to insert into DB2 those rows that aren't already there, and pick up with the next sequential COL1 value...
But we can't (I don't think) make Col1 an Identity column since Col3 already is an identity column. How can we leave col3 as an identity column, and automatically increment Col1, leaving the existing columns intact.
(The basic SQL comand is, of course,
INSERT into DB2..TBL1 (col1 col2 col3)
SELECT col1 col2 col3 from DB1..TBL1
where DB1..TBL1.Col1 not in (select Col1 from DB2.TBL1)
We're just need a way to populate Col1 in DB2 with the next sequential value. Thanks in advance for your help!
DB1..TBL1 has these columns:
Col1: primary key integer
Col2: text
Col3: Identity column
DB2..TBL1 has the same structure, and ALSO already has data in it, that we want to preserve.
We want to INSERT in DB2 those rows from DB1 that are not already in DB2.
The problem is that we can't just insert all the rows and columns from DB1 into DB2 since DB2 has Col1 already populated, and we can't overwrite those.
Basically, we need to insert into DB2 those rows that aren't already there, and pick up with the next sequential COL1 value...
But we can't (I don't think) make Col1 an Identity column since Col3 already is an identity column. How can we leave col3 as an identity column, and automatically increment Col1, leaving the existing columns intact.
(The basic SQL comand is, of course,
INSERT into DB2..TBL1 (col1 col2 col3)
SELECT col1 col2 col3 from DB1..TBL1
where DB1..TBL1.Col1 not in (select Col1 from DB2.TBL1)
We're just need a way to populate Col1 in DB2 with the next sequential value. Thanks in advance for your help!