SQL Server Bulk Insert Update from CSV? -
i'm importing csv file sql server. problem need update if rows found, haven't found insert update equivalent or similar it.
this current code:
bulk insert actuals_financials_temp '\\strmv3302\temp\actuals_financials_temp.csv' (fieldterminator = ',', rowterminator = '\n', firstrow = 2)
is there way update rows matching keys? or @ least ignore them rest uploaded , bulk update?
not directly, no. need bulk insert
staging table , update existing records , insert missing records. try local temp table (i.e. #tablename
) first.
technically speaking, either of following (both of use openrowset):
- skip staging table , use
openrowset(bulk...)
update , insert queries. have tested, though, see if cost of reading file twice worth savings of not having read temp table (which writes disk). possible using staging table might still better since first query, update, might auto-create statistics benefit second query, insert, since query need eitherleft join
orwhere not exists
. merge
alongopenrowset(bulk...)
,merge
has "issues" wouldn't try this.
Comments
Post a Comment