473,549 Members | 2,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ERROR 1062: Duplicate entry for key 2

I get that error when I try to update a table in my database

This is my table
+----+------------+---------+-----------+
| ID | CPRNR | NAME | SURNAME |
+----+------------+---------+-----------+
| 1 | 1234567890 | Ole | Hansson |
| 2 | 9876543211 | Ulla | Jensen |
| 3 | 1234321234 | Ole | Olsson |
| 4 | 7654321234 | Petter | ?es |
| 5 | 9876543213 | Ulla | Jensen |
+----+------------+---------+-----------+
5 rows in set (0.00 sec)

And my update lools like this:

update patient set cprnr='98765432 11',fornavn='Ul la',efternavn=' Jensen'
where id='5';

This is the error then :

ERROR 1062: Duplicate entry '9876543211' for key 2

I don't get it.

Carl

Jul 20 '05 #1
4 30014
newsfan wrote:
| 2 | 9876543211 | Ulla | Jensen | update patient set cprnr='98765432 11',fornavn='Ul la',efternavn=' Jensen'
where id='5';

This is the error then :

ERROR 1062: Duplicate entry '9876543211' for key 2


You have:
9876543211 in your table where id is 2 (like the error says)

And you try to insert this value:
9876543211 to your table, where id is 5

Looks like you have unique/key/etc. fieldtype for CPRNR which prevents
you from giving same value twice.
Jul 20 '05 #2
newsfan wrote:
| 2 | 9876543211 | Ulla | Jensen | update patient set cprnr='98765432 11',fornavn='Ul la',efternavn=' Jensen'
where id='5';

This is the error then :

ERROR 1062: Duplicate entry '9876543211' for key 2


You have:
9876543211 in your table where id is 2 (like the error says)

And you try to insert this value:
9876543211 to your table, where id is 5

Looks like you have unique/key/etc. fieldtype for CPRNR which prevents
you from giving same value twice.
Jul 20 '05 #3

I found out myself thatnks

"newsfan" <fa**********@h otmail.com> wrote in message
news:c7******** ***@news.cyberc ity.dk...
I get that error when I try to update a table in my database

This is my table
+----+------------+---------+-----------+
| ID | CPRNR | NAME | SURNAME |
+----+------------+---------+-----------+
| 1 | 1234567890 | Ole | Hansson |
| 2 | 9876543211 | Ulla | Jensen |
| 3 | 1234321234 | Ole | Olsson |
| 4 | 7654321234 | Petter | ?es |
| 5 | 9876543213 | Ulla | Jensen |
+----+------------+---------+-----------+
5 rows in set (0.00 sec)

And my update lools like this:

update patient set cprnr='98765432 11',fornavn='Ul la',efternavn=' Jensen'
where id='5';

This is the error then :

ERROR 1062: Duplicate entry '9876543211' for key 2

I don't get it.

Carl

Jul 20 '05 #4

I found out myself thatnks

"newsfan" <fa**********@h otmail.com> wrote in message
news:c7******** ***@news.cyberc ity.dk...
I get that error when I try to update a table in my database

This is my table
+----+------------+---------+-----------+
| ID | CPRNR | NAME | SURNAME |
+----+------------+---------+-----------+
| 1 | 1234567890 | Ole | Hansson |
| 2 | 9876543211 | Ulla | Jensen |
| 3 | 1234321234 | Ole | Olsson |
| 4 | 7654321234 | Petter | ?es |
| 5 | 9876543213 | Ulla | Jensen |
+----+------------+---------+-----------+
5 rows in set (0.00 sec)

And my update lools like this:

update patient set cprnr='98765432 11',fornavn='Ul la',efternavn=' Jensen'
where id='5';

This is the error then :

ERROR 1062: Duplicate entry '9876543211' for key 2

I don't get it.

Carl

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2337
by: Paul | last post by:
This is the currernt table strucure PHP:-------------------------------------------------------------------------------- CREATE TABLE games_developers ( developers_id int(5) NOT NULL auto_increment, developers_name varchar(255) NOT NULL default ' ', language_id int(5) NOT NULL default '0', PRIMARY KEY (developers_id,language_id)
0
3088
by: Gary Lundquest | last post by:
I have an application with MS Access 2000 as the front end and MySQL as the back end. All was well until I upgraded the MySQL (Linux) server. The Problem: I insert data into a cumulative table. Before when I did this, and there were duplicate entries, the duplicate entries were rejected and I got a return code with the number of affected...
1
838
by: Gary Lundquest | last post by:
It appears to me that MySQL version 4 returns an error messge when doing an Insert that results in duplicate entries. Version 3 did NOT return an error - it dropped the duplicate entries and ran to completion. Version 4 seems to STOP when it encounters a duplicate entry, so that the records before the duplicate are inserted and the records...
1
1369
by: Malcolm Dew-Jones | last post by:
Hello I need to detect duplicate errors when using mysql to insert a row in a php program. (I assume that the php version should not make a difference, but I don't know that for sure, which is why I mention php.) I am using mysql_error() and mysql_errno() - no problem there, but my question concerns the values they return in different...
3
6873
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records from rsSource into rsDest - if it finds a key violation then it deletes the current record from rsDest and adds the new record from rsSource. This...
8
13087
by: g_man | last post by:
I am trying trap Runtime error 3022 (duplicates) in the click event of a command button that closes the form. I have code in the Form_Error event that does a good job of providing a more meaningful error message than the default. It works in every situation except when the user clicks the close button. I am using Me.Dirty=False to force a...
5
22963
by: baur79 | last post by:
Hi guys i try to run this code in loop and to pass even the entry is duplicated def email_insert_in_db(email): sql="INSERT INTO emails (email) values ('%s') "%(email) db=_mysql.connect(host = "localhost", user = db_user, passwd = db_pass, db = db_name)
8
5011
by: Paul Furman | last post by:
How do I turn off MySQL error reporting? I set error_reporting(0); but that doesn't seem to be working.
10
3223
by: Phil Latio | last post by:
I am inserting data into user table which contains 5 fields, sounds simple enough normally but 2 of the fields are designated as UNIQUE. If someone does enter a value which already exists, how do I capture this specific error? Would it make more sense to actually run a SELECT query first and if that returned a result, then I use that for...
0
7521
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7451
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7473
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7810
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
764
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.