Mysql 4 vs Mysql 5 auto-increment field on insert
I've learned this along开发者_如何学JAVA 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?
Both the 4.1 and 5.0 docs state that 0 or NULL is required:
No value was specified for the AUTO_INCREMENT column, so MySQL assigned sequence numbers automatically. You can also explicitly assign NULL or 0 to the column to generate sequence numbers.
It does not matter, mysql internally still convert to integer
mysql> CREATE TABLE some_test ( id int(10) unsigned NOT NULL auto_increment, primary key(id)); Query OK, 0 rows affected (0.00 sec) mysql> insert into some_test values (''); Query OK, 1 row affected, 1 warning (0.00 sec) mysql> show warnings; +---------+------+------------------------------------------------------+ | Level | Code | Message | +---------+------+------------------------------------------------------+ | Warning | 1264 | Out of range value adjusted for column 'id' at row 1 | +---------+------+------------------------------------------------------+ 1 row in set (0.00 sec) mysql> select * from some_test; +----+ | id | +----+ | 1 | +----+ 1 row in set (0.00 sec)
However, I will suggest use 0 to avoid this warning
精彩评论