在MSSQL 2005中插入表记录 [英] Insert table records in MSSQL 2005

查看:90
本文介绍了在MSSQL 2005中插入表记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个表,如下所示-

Hi,

I have a table as following schema -

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

) 



我在[hotel_code]和[images]列上有复合键.

每周,我都会得到CSV文件,用于将记录插入表中.我只需要基于CSV到表的复合键插入新记录.

问题是CSV文件有超过2,00,000条记录,并且每周只有很少的新记录要插入.

因此,我面临一些性能下降的问题.

您能否建议一些替代方法来解决这种情况.

我试过子查询,不存在,区分.

我正在使用MSSQL 2005版本.



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.

推荐答案

尝试使用左联接:
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;


这篇关于在MSSQL 2005中插入表记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆