数据重复错误SQL批量 [英] data duplicate error sql bulk

查看:110
本文介绍了数据重复错误SQL批量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好...问候....

1.我从c#
读取了一个csv文件 2.存储在sql
2.然后..如果文件已更新..i再读一次..
2.再次存储在sql db中...
3.一切正常..直到..

4.我的csv文件中有重复的数据... vs2010说..在表名" CONSTRAINT中违反主键..无法插入重复的键..

Hi...greetings..

1. i read a csv file from c#
2. store in sql
2. then..if the file updated..i read it again..
2. store in sql db again...
3. everything working..untill..

4. there''s data duplicate in my csv file...vs2010 said..VIOLATION OF PRIMARY KEY IN "table name" CONSTRAINT..cannot insert duplicate key..

how to solve friendo!??

推荐答案

您可以先检查行是否存在,然后再决定要执行INSERT 还是.

另一个选择是使用 MERGE [
You can either first check if the row exists and then decide if you''re going to do INSERT or UPDATE.

Another option is to use MERGE[^] (depending on the version of your SQL Server)


您不允许重复-因此您需要以某种方式确保对现有键在数据库行上进行更新(而不是插入).
You cannot allow duplicates - so you need to somehow ensure that for existing keys you do an update on the database row (rather than do an insert).


这篇关于数据重复错误SQL批量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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