请问老师AUTO_INCREMENT=1;为什么不行啊

请问老师AUTO_INCREMENT=1;为什么不行啊

 user1 | CREATE TABLE `user1` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '编号',
  `username` varchar(20) NOT NULL COMMENT '用户',
  `age` tinyint(3) unsigned NOT NULL DEFAULT '18' COMMENT '年龄',
  `sex` enum('男','女','保密') NOT NULL DEFAULT '保密' COMMENT '性别',
  `addr` varchar(20) NOT NULL DEFAULT '北京',
  `married` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0代表未结婚,1代表已 结婚',
  `salary` float(8,2) NOT NULL DEFAULT '0.00' COMMENT '薪水',
  `userDesc` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> ALTER TABLE user1 AUTO_INCREMENT=1;
Query OK, 0 rows affected (0.10 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> SHOW CREATE TABLE user1;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| user1 | CREATE TABLE `user1` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '编号',
  `username` varchar(20) NOT NULL COMMENT '用户',
  `age` tinyint(3) unsigned NOT NULL DEFAULT '18' COMMENT '年龄',
  `sex` enum('男','女','保密') NOT NULL DEFAULT '保密' COMMENT '性别',
  `addr` varchar(20) NOT NULL DEFAULT '北京',
  `married` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0代表未结婚,1代表已 结婚',
  `salary` float(8,2) NOT NULL DEFAULT '0.00' COMMENT '薪水',
  `userDesc` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> ALTER TABLE user1 AUTO_INCREMENT=3;
Query OK, 0 rows affected (0.07 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> SHOW CREATE TABLE user1;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| user1 | CREATE TABLE `user1` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '编号',
  `username` varchar(20) NOT NULL COMMENT '用户',
  `age` tinyint(3) unsigned NOT NULL DEFAULT '18' COMMENT '年龄',
  `sex` enum('男','女','保密') NOT NULL DEFAULT '保密' COMMENT '性别',
  `addr` varchar(20) NOT NULL DEFAULT '北京',
  `married` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0代表未结婚,1代表已 结婚',
  `salary` float(8,2) NOT NULL DEFAULT '0.00' COMMENT '薪水',
  `userDesc` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.02 sec)


正在回答

登陆购买课程后可参与讨论,去登陆

2回答

可以设置AUTO_INCREMENT=1 呀,但前提是你的数据库中还没有数据,比如之前已经有 1,2,3,4 了,你再去设置自增从1开始就没有用了。

如果我的回答解决了你的问题,请采纳,祝学习愉快.


  • 慕盖茨8087740 提问者 #1
    老师请看纪录我设置了,当时没重置
    2019-03-31 13:51:03
  • 慕盖茨8087740 提问者 #2
    请问老师的意思是不是重置auto_Increment前提必须是数据表清空重置或者在没有表中没有已用上的auto_lncrement的数值情况才能设置为1?
    2019-03-31 19:30:09
  • 好帮手慕阿莹 回复 提问者 慕盖茨8087740 #3
    是的,auto_Increment设置为1的意思是,自增从1开始,如果同学的自增之前数据了就有了数据,它就没办法从1开始自增了呦。祝学习愉快
    2019-04-01 11:51:27
提问者 慕盖茨8087740 2019-03-31 19:29:51

请问老师的意思是不是重置auto_Increment前提必须是数据表清空重置或者在没有表中没有已用上的auto_lncrement的数值情况才能设置为1?

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师