Click here to Skip to main content
11,701,590 members (72,775 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: SQL-server-2005 SQL-Server , +

I have a table as following schema -

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 2-Nov-12 0:28am
Edited 2-Nov-12 0:35am
Milind Thakkar at 2-Nov-12 6:55am
How are you currently doing? Are you passing data to SP?
vikram_shinde at 2-Nov-12 7:06am
It's in initial stage so I haven't created SP. Just trying using simple query.
Milind Thakkar at 2-Nov-12 7:28am
front-end ? c# ? or no front end ?
vikram_shinde at 2-Nov-12 7:35am
c# webapp.
Wants to send csv file with web request.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try using a left join:
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;

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

  Print Answers RSS
0 OriginalGriff 324
1 Maciej Los 275
2 Sergey Alexandrovich Kryukov 250
3 Mika Wendelius 189
4 CHill60 110
0 OriginalGriff 8,274
1 Sergey Alexandrovich Kryukov 7,317
2 CPallini 4,912
3 Maciej Los 4,146
4 Mika Wendelius 3,556

Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 2 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100