暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

MySQL自增列测试

原创 何权林 2020-03-30
768

MySQL自增列测试(DB:5.7.27 OS:CentOS7.6)

情景1:创建包含自增列的新表测试
mysql> create table test05 (id int unsigned auto_increment);
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
结论:自增列必须为主键

情景2:创建包含自增列的新表,自增值直接从最大开始,添加新值
mysql> create table test06 (id int unsigned primary key auto_increment ) auto_increment=4294967295;
Query OK, 0 rows affected (0.02 sec)
或者
create table test06 (id int unsigned unique auto_increment ) auto_increment=4294967295;
Query OK, 0 rows affected (0.02 sec)

mysql> insert into test06 values();
Query OK, 1 row affected (0.00 sec)

mysql> insert into test06 values();
ERROR 1062 (23000): Duplicate entry ‘4294967295’ for key ‘PRIMARY’
mysql> select * from test06;
±-----------+
| id |
±-----------+
| 4294967295 |
±-----------+
1 row in set (0.00 sec)

mysql>
结论:自增值超过范围后会报主键重复,无法插入数据。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论