请问老师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)
正在回答
可以设置AUTO_INCREMENT=1 呀,但前提是你的数据库中还没有数据,比如之前已经有 1,2,3,4 了,你再去设置自增从1开始就没有用了。
如果我的回答解决了你的问题,请采纳,祝学习愉快.
请问老师的意思是不是重置auto_Increment前提必须是数据表清空重置或者在没有表中没有已用上的auto_lncrement的数值情况才能设置为1?
- 参与学习 人
- 提交作业 357 份
- 解答问题 8016 个
本阶段将带你学习MySQL数据库,JDBC接口,MyBatis框架等,带你掌握的数据的存放和管理。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星