How to skip all the column names in MySQL when the table has auto increment primary key?

Posted by Jian Lin on Stack Overflow See other posts from Stack Overflow or by Jian Lin
Published on 2010-04-24T12:15:20Z Indexed on 2010/04/24 12:23 UTC
Read the original article Hit count: 277

Filed under:
|
|
|
|

A table is:

mysql> desc gifts;
+---------------+-------------+------+-----+---------+----------------+
| Field         | Type        | Null | Key | Default | Extra          |
+---------------+-------------+------+-----+---------+----------------+
| giftID        | int(11)     | NO   | PRI | NULL    | auto_increment |
| name          | varchar(80) | YES  |     | NULL    |                |
| filename      | varchar(80) | YES  |     | NULL    |                |
| effectiveTime | datetime    | YES  |     | NULL    |                |
+---------------+-------------+------+-----+---------+----------------+

the following is ok:

mysql> insert into gifts
    -> values (10, "heart", "heart_shape.jpg", now());
Query OK, 1 row affected (0.05 sec)

but is there a way to not specify the "10"... and just let each one be 11, 12, 13... ?

I can do it using

mysql> insert into gifts (name, filename, effectiveTime)
    -> values ("coffee", "coffee123.jpg", now());
Query OK, 1 row affected (0.00 sec)

but the column names need to be all specified. Is there a way that they don't have to be specified and the auto increment of primary key still works? thanks.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql