mysql,在除id以外的所有行中插入值

hs1rzwqc  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(299)

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

xytpbqjk

xytpbqjk1#

如果你的 id 是自动递增的,如果您插入 NULL . 因此,您可以执行以下操作:

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;

相关问题