Mysql如何设置id自增

(1)设置自增

  • 方案一:
CREATE TABLE IF NOT EXISTS `user`(
   `id` INT UNSIGNED AUTO_INCREMENT,
   `name` VARCHAR(100) NOT NULL,
   `sex` VARCHAR(40) NOT NULL,
   `age` INT(11),
   PRIMARY KEY ( `id` )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
  • 方案二:
alter table user modify id int auto_increment;

(2)设置自增起始值

show variables like 'auto_increment%';

在这里插入图片描述

set auto_increment_offset=10;
show variables like 'auto_increment%';

在这里插入图片描述

(3)设置自增区间

set auto_increment_increment=10;
show variables like 'auto_increment%';

在这里插入图片描述
笔记:
如何修改表名?

alter table old_table rename to new_table;

猜你喜欢

转载自blog.csdn.net/weixin_43166227/article/details/109534902
今日推荐