At 08:05 PM 10/16/2010, you wrote:
Hello,
I have a table which has the ID key with auto_increment and which is a
primary key.
If I insert the table with the id value which is generated by the
program, for example,
insert table (id, user_name, age) values (1000, 'kenn', 30);
the value 1000 is inserted forcely, not generated by database automatically.
Will this cause problem?
Thanks.
It is not going to cause a problem but it defeats the purpose of having an
auto-inc column. After executing the SQL statement, the next Id inserted
will be 1000. It is much better to let the table determine the next
auto-inc value by using:
insert table (id, user_name, age) values (NULL, 'kenn', 30);
If you want to get the value of the Id that was used, simply reference the
variable Last_Insert_Id as in:
select Last_Insert_Id;
See:
http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html
Mike
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=mo...@fastmail.fm
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=arch...@jab.org