关于插入纪录时进 set id=0 无效的问题

2016-01-11 19:57:51 +08:00
 quietin

+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| desc | varchar(100) | NO | | NULL | |
+------------+--------------+------+-----+---------+----------------+

对于这样的表,如果插入 id 为 0 的纪录,会插入成功,但插入的纪录 id 不为 0 而是自增后的值,但是 id 为-1 时,则能成功插入并且 id=-1 ,这是为什么?

insert into content_cornermark set id=-1, content_cornermark.desc='无';

2295 次点击
所在节点    MySQL
3 条回复
geeglo
2016-01-11 20:01:27 +08:00
-1 在 int 的范围中
msg7086
2016-01-12 02:15:20 +08:00
Let me google that for you:
http://stackoverflow.com/a/1142588
quietin
2016-01-12 15:14:37 +08:00
@geeglo 0 难道不是 int 么

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/249966

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX