我创建具有默认值“ 1”的列的表
create table int_1 (
id int not null auto_increment,
value int default 1,
primary key (id)
);
Run Code Online (Sandbox Code Playgroud)
命令
insert into int_1 values(1, null) on duplicate key update value = null;
Run Code Online (Sandbox Code Playgroud)
总是返回结果
1 row(s) affected
Run Code Online (Sandbox Code Playgroud)
但记录在第一次执行后确实发生了更改(插入)。但是,如果我使用默认值“ 0”创建表,则所有功能均按预期工作:
create table int_0 (
id int not null auto_increment,
value int default 0,
primary key (id)
);
insert into int_0 values(1, null) on duplicate key update value = null;
Run Code Online (Sandbox Code Playgroud)
返回
0 row(s) affected
Run Code Online (Sandbox Code Playgroud)
第二次运行后“插入重复键”
在MySQL 5.7,8.0上检查
有这种行为的解释吗?