Search code examples
mysqlsqlmysql-error-1062

#1062 - Duplicate entry for key 'PRIMARY'


So my MySQL database is behaving a little bit wierd. This is my table:

Name shares id  price   indvprc
cat   2     4   81      0
goog  4     4   20      20
fb    4     9   20      20

I'm getting this #1062 error when I try to insert into the table. So I looked into it further and realized that when I try to insert values into the table, in which the name and shares values are the same, it will return the #1062 error. For example, If i inserted:

fb    4      6     20   20 

It would return an error. But if i changed the shares number to 6, it would run fine. Is it because of one of my columns that could be unique, or is it just something with mysql?


Solution

  • You need to remove shares as your PRIMARY KEY OR UNIQUE_KEY