Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Violation of PRIMARY KEY constraint 'PK__student__3213E83FBB0F63EB'. Cannot insert duplicate key in object 'dbo.student'. The duplicate key value is (1).

this is error massage,when created new table and try to insert the values
,,what is the solution plz?


What I have tried:

i checked syntax repeatedly, also checked that primary key is not repeated from my side
Posted
Updated 2-Mar-23 1:37am
Comments
CHill60 2-Mar-23 6:14am    
"also checked that primary key is not repeated from my side" - nevertheless,you are trying to insert a record with a primary key that already exists on that database
Member 15627495 2-Mar-23 7:22am    
if your 'primary key' is "auto inc : A.I", don't write the belonged field in your "insert" query.
the Db engine will do it for you.

1 solution

Primary keys must - by definition - be unique: you cannot enter a second PK that has the same value - and the error message is pretty explicit about this.

So start by looking at your values and how you INSERT them to the DB; check that you are using the DB you think you are; that you are using the table you think you are; and look closely at your code to find out how you are passing the data to the DB Engine.

The DB Engine doesn't raise this error spontaneously: it is being passed a PK field value that would duplicate an existing one!

Sorry, but we can't help you fix this: we have no access to your DB, your data, or your code - and you need all three to start working this out!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900