为 MySQL 表中的列设置类似的值?
您可以借助 update 命令为一列所有记录设置值。
如果您想为一列中的所有记录设置 NULL 值,语法如下 -
update yourTableName set yourColumnName = NULL;登录后复制
update yourTableName set yourColumnName = ’’;登录后复制
mysql> create table StudentDemo −> ( −> Studentid int, −> StudentName varchar(100), −> Age int −> ); Query OK, 0 rows affected (0.64 sec)登录后复制
mysql> insert into StudentDemo values(1,'Johnson',23); Query OK, 1 row affected (0.18 sec) mysql> insert into StudentDemo values(2,'Carol',24); Query OK, 1 row affected (0.16 sec) mysql> insert into StudentDemo values(3,'David',20); Query OK, 1 row affected (0.18 sec) mysql> insert into StudentDemo values(4,'Bob',21); Query OK, 1 row affected (0.19 sec)登录后复制
mysql> select *from StudentDemo;登录后复制登录后复制
+-----------+-------------+------+ | Studentid | StudentName | Age | +-----------+-------------+------+ | 1 | Johnson | 23 | | 2 | Carol | 24 | | 3 | David | 20 | | 4 | Bob | 21 | +-----------+-------------+------+ 4 rows in set (0.00 sec)登录后复制
mysql> update StudentDemo set Age=NULL; Query OK, 4 rows affected (0.14 sec) Rows matched: 4 Changed: 4 Warnings: 0登录后复制
mysql> select *from StudentDemo;登录后复制登录后复制
+-----------+-------------+------+ | Studentid | StudentName | Age | +-----------+-------------+------+ | 1 | Johnson | NULL | | 2 | Carol | NULL | | 3 | David | NULL | | 4 | Bob | NULL | +-----------+-------------+------+ 4 rows in set (0.00 sec)登录后复制