Mysql 4 vs Mysql 5 插入时自动递增字段
我一路上学到了这一点,但不知道在哪里读到或听到它,因为我在网上找不到任何支持它的东西,但我记得当从 mysql4.x 升级到 mysql5.x 时,其中之一所需的更改是插入的自动增量字段必须从 '' 更改为 NULL(如果包含)。
我知道无论如何都不需要在插入中包含它,但只是为了兴趣点......
Mysql 4.x 将允许: INSERT INTO TABLE (table_id, name, location) VALUES ('', 'john', 'NY');
但 mysql 5.x 必须有: INSERT INTO TABLE (table_id, name, location) VALUES (NULL, 'john', 'NY');
我在 mysql 的网站上找不到任何信息来支持这一点,但我知道它在 mysql 5.x 中抛出一个错误,并且知道它在 4.x 中与 '' 一起工作,但这在哪里记录?
I've learned this along the way but can't figure out where I read it or heard it, as there is nothing I have found online supporting it, but I remember that when upgrading from mysql4.x to mysql5.x, one of the required changes was that the auto-increment field for inserts had to change from '' to NULL if it was included.
I know its not required to have in the insert anyway, but just for point of interest...
Mysql 4.x would allow:
INSERT INTO TABLE (table_id, name, location) VALUES ('', 'john', 'NY');
But mysql 5.x had to have:
INSERT INTO TABLE (table_id, name, location) VALUES (NULL, 'john', 'NY');
I can't find any information on mysql's site to support this, but I know for a fact it throws an error in mysql 5.x and know it worked with '' in 4.x, but where is this documented?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
4.1 和 5.0 文档指出需要 0 或 NULL:
Both the 4.1 and 5.0 docs state that 0 or NULL is required:
没关系,mysql内部仍然转换为整数
但是,我建议使用0来避免这个警告
It does not matter, mysql internally still convert to integer
However, I will suggest use 0 to avoid this warning