为此,请按照以下语法使用SET yourColumnName = NULL-
update yourTableName set yourColumnName=NULL where yourColumnName=yourValue;
让我们首先创建一个表-
mysql> create table DemoTable1914 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Code varchar(20) )AUTO_INCREMENT=1001;
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1914(Code) values('John101'); mysql> insert into DemoTable1914(Code) values('234David'); mysql> insert into DemoTable1914(Code) values('100_Mike');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1914;
这将产生以下输出-
+------+----------+ | Id | Code | +------+----------+ | 1001 | John101 | | 1002 | 234David | | 1003 | 100_Mike | +------+----------+ 3 rows in set (0.00 sec)
这是查找值并替换为NULL的查询-
mysql> update DemoTable1914 set Code=NULL where Code='100_Mike'; Rows matched: 1 Changed: 1 Warnings: 0
让我们再次检查表记录-
mysql> select * from DemoTable1914;
这将产生以下输出-
+------+----------+ | Id | Code | +------+----------+ | 1001 | John101 | | 1002 | 234David | | 1003 | NULL | +------+----------+ 3 rows in set (0.00 sec)