Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,

I have a table as following schema -

SQL
CREATE TABLE [dbo].[hotel_info](
	[hotel_code] [varchar](20) NOT NULL,
	[images] [varchar](100) NULL

) 


I have composite key on [hotel_code] and [images] columns .

Weekly, I get CSV file for inserting records into table. I have to insert only new records based on composite key from CSV to table.

Problem is CSV file has more than 2,00,000 records and there are only few new records weekly to insert.

So I am facing some performance degradation issue.

Could you please suggest few alternative approaches to tackle this scenario.

I have tried Subquery, NOT EXISTS, DISTINCT.

I am using MSSQL 2005 edition.
Posted
Updated 2-Nov-12 0:35am
v2
Comments
MT_ 2-Nov-12 6:55am    
How are you currently doing? Are you passing data to SP?
vikram_shinde 2-Nov-12 7:06am    
It's in initial stage so I haven't created SP. Just trying using simple query.
MT_ 2-Nov-12 7:28am    
front-end ? c# ? or no front end ?
vikram_shinde 2-Nov-12 7:35am    
c# webapp.
Wants to send csv file with web request.

1 solution

Try using a left join:
SQL
INSERT INTO hotel_info (hotel_code, images) 
SELECT A.hotel_code, A.images 
FROM importtable A 
LEFT JOIN hotel_info B ON A.hotel_code = B.hotel_code
                         AND A.images = B.images 
WHERE B.hotel_code IS NULL;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900