dongyu4455 2012-12-30 20:54
浏览 72
已采纳

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.

  • 写回答

1条回答 默认 最新

  • douzhan1994 2012-12-30 20:57
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示