我如何解决不能在对象中插入重复键? [英] How Do I Solve Cannot Insert Duplicate Key In Object ?
本文介绍了我如何解决不能在对象中插入重复键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Msg 2627,Level 14,State 1,Line 1
违反PRIMARY KEY约束'PK_table123_1'。无法在对象'dbo.table123'中插入重复键。重复键值为(12,23,57,2007-2008,00001010200,01,MON / MY / ING / 9 / 06,10 / 10 / 2008,730,377)。
声明已被终止。
如果数据相同则很好..
i想不做任何改变...
如果没有匹配则插入....其中所有字段都为空。
Msg 2627, Level 14, State 1, Line 1
Violation of PRIMARY KEY constraint 'PK_table123_1'. Cannot insert duplicate key in object 'dbo.table123'. The duplicate key value is (12, 23, 57, 2007-2008, 00001010200, 01, MON/MY/ING/9/06, 10/12/2008, 730, 377).
The statement has been terminated.
well if the data is same..
i would like to make no change...
if no matching then insert ....where all fields are null.
推荐答案
查看此链接可能会对您有所帮助。
http://stackoverflow.com/questions/3407857/only-inserting-a-row-if-its-not-already-there [ ^ ]
Check this link it may help you.
http://stackoverflow.com/questions/3407857/only-inserting-a-row-if-its-not-already-there[^]
如果不存在,请使用它
Beter you use if not exist
IF NOT EXISTS (select 1 from tablename where Id = @id)
BEGIN
insert into tablename (Id, Name, Address)
values (@id, @Name, @Address)
END
这篇关于我如何解决不能在对象中插入重复键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文