MySQL,在除id之外的所有行中插入值

MySQL,在除id之外的所有行中插入值,mysql,sql,Mysql,Sql,除了id(我已经设置为PK)之外,如何在表中插入值而不指定所有列名?如果您的id是自动递增的,那么如果您插入NULL,MySQL仍将自动递增。因此,您可以执行以下操作: create table t ( id int auto_increment primary key, x int ); insert into t select null, 2; insert into t select null, 3; 也就是说,我建议(几乎)总是在insert中包含所

除了id(我已经设置为PK)之外,如何在表中插入值而不指定所有列名?

如果您的
id
是自动递增的,那么如果您插入
NULL
,MySQL仍将自动递增。因此,您可以执行以下操作:

create table t (
    id int auto_increment primary key,
    x int
);

insert into t
    select null, 2;

insert into t
    select null, 3;
也就是说,我建议(几乎)总是在
insert
中包含所有列。因此,我强烈建议:

insert into t (x)
    select 2;

insert into t (x)
    select 3;

如果您的
id
是自动递增的,那么如果您插入
NULL
,MySQL仍将自动递增。因此,您可以执行以下操作:

create table t (
    id int auto_increment primary key,
    x int
);

insert into t
    select null, 2;

insert into t
    select null, 3;
也就是说,我建议(几乎)总是在
insert
中包含所有列。因此,我强烈建议:

insert into t (x)
    select 2;

insert into t (x)
    select 3;
插入t值(默认值,1,2,3…)
插入t值(默认值,1,2,3…)的可能重复