February 28, 2020 at 6:15 pm
Hello, I think this is a simple query but it is being a long time I haven't write queries. If you can help me I will appreciate it a lot.
I need to copy some data from one table to another table. This is the statement I am trying to use:
insert into ItemDetail(ItemMasterId,Content,ItemMasterAttributeId)
Select distinct itemid,Qty,Itemattributeid from #tempitemdetail
and Im getting the following error:
Msg 2627, Level 14, State 1, Line 86
Violation of PRIMARY KEY constraint 'PK_ItemDetail'. Cannot insert duplicate key in object 'dbo.ItemDetail'. The duplicate key value is (11171, 18).
The statement has been terminated.
The table Itemdetail has a lot of attributes for same Itemid. I just need to add a new value for a new attribute id.
Could you help me to figure it out how to write my query to work? Thanks
February 28, 2020 at 7:00 pm
We don't have enough information to tell you exactly what the problem is, but the error message gives you a LOT of information.
dbo.ItemDetail
has a primary key PK_ItemDetail
.ItemMasterId
and ItemMasterAttributeId
.Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply