【发布时间】:2018-06-13 14:21:17
【问题描述】:
如何在不指定所有列名的情况下在表中插入除 id(我已设置为 PK)之外的值?
【问题讨论】:
-
insert into t values (default, 1, 2, 3 ...)?
如何在不指定所有列名的情况下在表中插入除 id(我已设置为 PK)之外的值?
【问题讨论】:
insert into t values (default, 1, 2, 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;
【讨论】:
INSERT 中”?