开发者

How to tell phpMyAdmin to use next auto increment value during insert?

If you try to insert a new record through phpMyAdmin interface to a table that has auto increment primary index field, it requires you to manually enter value for this field. If you d开发者_运维技巧on't enter anything it throws an error. How to make it just use auto increment value?


insert into tbl (id,...) values (0,...);  <-- use zero

If a user specifies NULL or 0 for the AUTO_INCREMENT column in an INSERT, InnoDB treats the row as if the value had not been specified and generates a new value for it.


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.


Try to pass NULL value to the primary field. Below is the sample query..

insert into tbl (id,...) values (NULL,...);

Hope this will help.

Thanks!

Hussain.


I was using PreparedStatement and I was having a hard time using the autoincrement. In my case you just have to do this

preparedStatement.setInt(1, 0);

1 is the index of the column , 0 increments the value to the next one in the sequence.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜