el dorado
el dorado

Reputation: 11

Duplicate entry '1944994' for key 1

Can anyone please explain this to me?

    mysql> select * from heartbeat order by id desc limit 20;
    +---------+---------------------+---------------------------------------------------------+
    | id      | date                | node                                                    |
    +---------+---------------------+---------------------------------------------------------+
    | 1944993 | 2013-03-22 12:06:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944992 | 2013-03-22 12:05:59 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944991 | 2013-03-22 12:05:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944990 | 2013-03-22 12:05:07 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944989 | 2013-03-22 12:05:07 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944988 | 2013-03-22 12:05:07 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944987 | 2013-03-21 21:12:59 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944986 | 2013-03-21 21:12:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944985 | 2013-03-21 21:11:59 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944984 | 2013-03-21 21:11:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944983 | 2013-03-21 21:10:59 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944982 | 2013-03-21 21:10:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944981 | 2013-03-21 21:09:59 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944980 | 2013-03-21 21:09:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944979 | 2013-03-21 21:08:59 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944978 | 2013-03-21 21:08:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944977 | 2013-03-21 21:07:59 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944976 | 2013-03-21 21:07:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944975 | 2013-03-21 21:06:59 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    | 1944974 | 2013-03-21 21:06:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
    +---------+---------------------+---------------------------------------------------------+
    20 rows in set (0.01 sec)

Trying to insert the next value..

insert into heartbeat values(1944994, '2013-03-22 12:06:29','CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com');

ERROR 1062 (23000): Duplicate entry '1944994' for key 1

ensured that the value is not there..

select * from heartbeat where id=1944994;
Empty set (0.00 sec)

    mysql> desc heartbeat;
    +-------+--------------+------+-----+---------+----------------+
    | Field | Type         | Null | Key | Default | Extra          |
    +-------+--------------+------+-----+---------+----------------+
    | id    | bigint(20)   | NO   | PRI | NULL    | auto_increment |
    | date  | datetime     | YES  |     | NULL    |                |
    | node  | varchar(255) | YES  |     | NULL    |                |
    +-------+--------------+------+-----+---------+----------------+
    3 rows in set (0.05 sec)

    mysql> SHOW VARIABLES LIKE "%version%";
    +-------------------------+-------------------------------+
    | Variable_name           | Value                         |
    +-------------------------+-------------------------------+
    | protocol_version        | 10                            |
    | version                 | 5.0.51b-community-nt          |
    | version_comment         | MySQL Community Edition (GPL) |
    | version_compile_machine | ia32                          |
    | version_compile_os      | Win32                         |
    +-------------------------+-------------------------------+
    5 rows in set (0.00 sec)

Is there anybody who got the same issue? Why I am getting exception at 1944994?

Upvotes: 0

Views: 84

Answers (1)

divyabharathi
divyabharathi

Reputation: 2237

Don't supply value for that column when inserting rows since id is auto_increment. so MySQL assigned sequence numbers automatically.You can also explicitly assign NULL or 0 to the column to generate sequence numbers.

Upvotes: 2

Related Questions