Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am inserting record into database it gives error:Duplicate entry '0' for key 'PRIMARY'. i am using mysql database. please help me?
Posted
Updated 15-Mar-14 0:24am
v2
Comments
Maciej Los 15-Mar-14 9:35am    
Please, be more specific and provide more details about your issue. We can't read in your mind and we don't see your screen. Improve question and provide details about the structure of table and the way you are trying to add data.

I can guess that You are inserting same value in your primary key field. SO I will be suggest to you that you should set is identity field --Yes and set seed value 1 and auto increment 1.


SQL
CREATE TABLE Persons
(
ID int IDENTITY(1,1) PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)

Thanks.
 
Share this answer
 
Comments
Member 9027346 15-Mar-14 6:27am    
already i set id is autoincrement.
Sandeep Singh Shekhawat 15-Mar-14 6:33am    
Please check your Identity seed and Identity increment value for id field and (is Identity) should be Yes. How could you insert 0 (zero) in your table already?
Member 9027346 15-Mar-14 6:54am    
i have already 2 record in table.error comes at the time of inserting 3 record.
Sandeep Singh Shekhawat 15-Mar-14 7:04am    
What is Ids of both record these are already inserted in your database table? These rows ids should be 1 and 2 respectively.
Member 9027346 15-Mar-14 7:05am    
yes,ids are 1,2
The primary key must contains unique values ,so you can't enter duplicate values.
 
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