![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, What's the best way to import data from a csv file into a table in which some of the rows already exist in the table? Assume the primary key value is in the csv file. So I'm basically looking for a "replace" operation on that row. thanks, Deac |
#3
| |||
| |||
|
|
Hi, What's the best way to import data from a csv file into a table in which some of the rows already exist in the table? Assume the primary key value is in the csv file. So I'm basically looking for a "replace" operation on that row. thanks, Deac |
#4
| |||
| |||
|
|
Without doubt the fastest and easiest way is to import to staging table first. You can then use TSQL to do the manipulation. -- Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP) www.SQLDTS.com - The site for all your DTS needs. www.SQLIS.com - You thought DTS was good. here we show you the new stuff. www.konesans.com - Consultancy from the people who know "deacdb" <deacdb2 (AT) hotmail (DOT) com> wrote in message news:eobMV5UcFHA.2936 (AT) tk2msftngp13 (DOT) phx.gbl... Hi, What's the best way to import data from a csv file into a table in which some of the rows already exist in the table? Assume the primary key value is in the csv file. So I'm basically looking for a "replace" operation on that row. thanks, Deac |
#5
| |||
| |||
|
#6
| |||
| |||
|
|
1. Use NOT EXISTS (usually performs better than NOT IN) or use an outer join: INSERT INTO T (...) SELECT S. ... FROM S LEFT JOIN T ON S.key_col = T.key_col WHERE T.key_col IS NULL 2. UPDATE with a join. Do the UPDATE before the INSERT so that the target table is smaller and you don't hit the same rows you just inserted. -- David Portas SQL Server MVP -- |
![]() |
| Thread Tools | |
| Display Modes | |
| |