How can i give customized auto increment in mysql

Discussion in 'MySQL' started by reporterdeluna, Jul 23, 2010.

  1. #1
    I want to increment in mysql by 2 i.e. 1,3,5 but by just using autoincrement its incremented by 1. Can anyone tell me how can i increment by 2 in mysql table?
     
    reporterdeluna, Jul 23, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi,

    Try:
    
    ALTER TABLE TableName AUTO_INCREMENT=2;
    
    Code (markup):
    Create table example:
    
    CREATE TABLE `TableName` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
       field1 TEXT,
      PRIMARY KEY (`id`)
    ) AUTO_INCREMENT=2;
    
    Code (markup):
    Regards :)
     
    koko5, Jul 23, 2010 IP
  3. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    When you change AUTO_INCREMENT you are just setting the start point for all future increments. It doesn't change the increment offset.
    Try doing this before you create the table:
    
    SET @@auto_increment_offset=5;
    
    Code (markup):
     
    Deacalion, Jul 23, 2010 IP