开发者

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

开发者 https://www.devze.com 2022-12-27 20:21 出处:网络
A table is: mysql> desc gifts; +---------------+-------------+------+-----+---------+----------------+

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)
    -> v开发者_开发知识库alues ("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.


values (NULL, "heart", "heart_shape.jpg", now());
0

精彩评论

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

关注公众号