AUTO_INCREMENT分两个地方

I came across following sql statements and you can see that AUTO_INCREMENT is in two different places. Can you explain the different, I know the first one is auto incrementing id. But what does the second one mean?

CREATE TABLE `categories`(
    `id` int(11) NOT NULL AUTO_INCREMENT,
     `name` varchar(100) NOT NULL,
     `image_path` varchar(200) NOT NULL,
      PRIMARY KEY(`id`)
) ENGINE = InnoDB;

Second statement.

CREATE TABLE `categories`(
     `id` int(11) NOT NULL AUTO_INCREMENT,
     `name` varchar(100) NOT NULL,
     `image_path` varchar(200) NOT NULL,
     PRIMARY KEY(`id`)
) ENGINE = InnoDB  DEFAULT CHARSET = latin1 AUTO_INCREMENT=4 ;

I referenced http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html. But I couldn't find anything.

The AUTO_INCREMENT in the second statement sets the first number to be used in the id at 4.

`id` int(11) NOT NULL AUTO_INCREMENT

Sets the column name and tells the DB to auto increment the number when a new row is added.

) ENGINE = InnoDB  DEFAULT CHARSET = latin1 AUTO_INCREMENT=4 ;

Sets the Engine used for the table, the charset and that it should start numbering at 4, not 1.

CREATE TABLE explains this in a bit more detail.

  • AUTO_INCREMENT

The initial AUTO_INCREMENT value for the table. In MySQL 5.0, this works for MyISAM and MEMORY tables. It is also supported for InnoDB as of MySQL 5.0.3.