使用MySQL更新具有空值或非空值的表中的所有字段
让我们首先创建一个表-
create table DemoTable -> ( -> Id int, -> Name varchar(20) -> );
使用插入命令在表中插入一些记录-
insert into DemoTable values(10,NULL); insert into DemoTable values(NULL,'David'); insert into DemoTable values(NULL,NULL);
使用select语句显示表中的所有记录-
select * from DemoTable;
+------+-------+ | Id | Name | +------+-------+ | 10 | NULL | | NULL | David | | NULL | NULL | +------+-------+ 3 rows in set (0.00 sec)
这是使用空值或非空值更新表中所有字段的查询-
update DemoTable set Name='Robert' where Id IS NULL or Name IS NULL; Rows matched: 3 Changed: 3 Warnings: 0
让我们再次检查表记录-
select * from DemoTable;
这将产生以下输出-
+------+--------+ | Id | Name | +------+--------+ | 10 | Robert | | NULL | Robert | | NULL | Robert | +------+--------+ 3 rows in set (0.00 sec)
热门推荐
2 红丝绒戚风蛋糕
3 夹心小甜点
4 南瓜甜点
6 粘米粉蒸蛋糕
7 酸奶华夫饼
9 红柚鸡蛋糕
10 葡萄干蛋糕
11 紫薯蛋糕卷
13 纸杯裱花小蛋糕
14 果酱奶酪蛋糕
15 日式樱花蔓越莓大福
16 草莓蛋糕卷
17 卡仕达长崎杯子蛋糕