- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why does the following error occur in MySQL: ERROR 1062 (23000): Duplicate entry?
Let’s say you have set column values as unique key and try to insert duplicate values in the table. This will lead to ERROR 1062 (23000): Duplicate entry.
Let us first create a table -
mysql> create table DemoTable776 ( FirstValue int, SecondValue int, unique key(FirstValue,SecondValue) ); Query OK, 0 rows affected (0.74 sec)
Insert some records in the table using insert command. While inserting duplicate value, the same error arises as shown below -
mysql> insert into DemoTable776 values(10,20); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable776 values(10,40); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable776 values(40,20); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable776 values(10,20); ERROR 1062 (23000): Duplicate entry '10-20' for key 'FirstValue'
Display all records from the table using select statement -
mysql> select *from DemoTable776;
This will produce the following output -
+------------+-------------+ | FirstValue | SecondValue | +------------+-------------+ | 10 | 20 | | 10 | 40 | | 40 | 20 | +------------+-------------+ 3 rows in set (0.00 sec)
- Related Articles
- When the MySQL delimiter error occur?
- Why does comparing types in MySQL won’t raise an error?
- How to add duplicate varchar values without displaying error in MySQL?
- Display an error while inserting duplicate records in a MySQL table
- Why the following is showing an error in MySQL: INSERT INTO yourTableName VALUE(yourValue1,yourValue2,.......N);?
- Resolve MySQL ERROR 1064 (42000): You have an error in your syntax?
- Why does menstruation occur?
- Declare syntax error in MySQL Workbench?
- Fix MySQL Database Error #1064?
- Why the #1054 - Unknown column error occurs in MySQL and how to fix it?
- Can we know the last MySQL error?
- Why accessing an array out of bounds does not give any error in C++?
- How to prevent MySQL double insert (duplicate entry)?
- MySQL Error - #1046 - No database selected
- comp_err - Compile MySQL Error Message File

Advertisements