让我们首先创建一个表-
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)