Auto Increment jumping to 2147483647 - mySQL

Discussion in 'MySQL' started by amaze, Sep 7, 2007.

  1. #1
    Hi,

    I have set up a table in mySQL (see below) and set the pkVoucherId to be auto incremenet and the unique key. The table was functioning correctly by auto incrementing the unique id. Now for some reason it trys to create the unique key of: 2147483647.

    ...and of course as it needs to be unique it complains about "dupe entry". Does anyone know why it has just started to do this and how to make it start counting from where it left off (2011)?

    Thanks

    CREATE TABLE `dvouchers` (
      `pkVoucherId` int(3) NOT NULL auto_increment,
      `code` varchar(12) NOT NULL default '1',
      `type` char(1) NOT NULL default '$',
      `count` int(3) unsigned NOT NULL default '0',
      `amount` int(3) unsigned default '0',
      `notes` text,
      `expiryDate` date default NULL,
      `fkUserAdminId` int(11) NOT NULL default '0',
      PRIMARY KEY  (`pkVoucherId`),
      UNIQUE KEY `pkVoucherId` (`pkVoucherId`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    Code (markup):
     
    amaze, Sep 7, 2007 IP
  2. Clark Kent

    Clark Kent Guest

    Messages:
    122
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    First Run this Query: and get maximum ID +1:
    select ifnull(max(announce_id),0)+1 from dvouchers

    Than Alter table with above number. Change xxx with above query result:
    ALTER TABLE dvouchers MODIFY pkVoucherId INT AUTO_INCREMENT, AUTO_INCREMENT = xxx ;
     
    Clark Kent, Sep 8, 2007 IP
  3. amaze

    amaze Active Member

    Messages:
    594
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Thank you! :)

    Is this a bug in mySQL? Why did it happen?

    Cheers
     
    amaze, Sep 8, 2007 IP
  4. amaze

    amaze Active Member

    Messages:
    594
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Hi,

    Can anyone explain why this happened? Is it a bug or did I do something wrong? I don't really want it to happen again as it obviously made the site die eeek!

    Thanks again!
     
    amaze, Sep 10, 2007 IP