Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Sun Foster
Aged Yak Warrior
515 Posts |
Posted - 2005-04-11 : 16:32:57
|
| How to code to insert only incresement records from table A to table B? |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-04-11 : 16:40:12
|
| What are incresement records?Do you mean keeping table B in sync with table A by only processing Inserted, Updated, or Deleted records from table A?Be One with the OptimizerTG |
 |
|
|
Sun Foster
Aged Yak Warrior
515 Posts |
Posted - 2005-04-13 : 10:18:37
|
| Table A in one server which users input data. Table B in another server which will import data from Table A every day. I need to code to insert only new data every day from A to B. |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-04-13 : 10:55:20
|
| Have you looked into Replication? That's sort of what it's for.If you want to do it manually, it depends on the structure of the table(s). Let's look at an ideal case where they have identical structures including a surrogate unique key (RowID) and a DateModified datetime column.--Get the tables on the same serverDTS TableA to TableB server.--Inserts:insert TableB (<collist>)Select <collist>from TableA aleft join TableB b ON a.rowid = b.rowidwhere b.rowid is NULL--updatesUpdate b set b.<col> = a.<col>from TableB bJOIN TableA a ON a.rowid = b.rowidwhere a.DateModified > b.DateModified--deletesdelete bfrom TableB Bleft join TableA a ON a.rowid = b.rowidwhere a.rowid is NULLBe One with the OptimizerTG |
 |
|
|
|
|
|