MySQL 更新列名并将 None 值设置为 N/A?
让我们首先创建一个表 -
mysql> create table DemoTable1903 ( FirstName varchar(20), LastName varchar(20) , Age int ); Query OK, 0 rows affected (0.00 sec)
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable1903 values('John','Smith',23); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1903 values('None','Miller',28); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1903 values('None','Taylor',26); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1903 values('Chris','Brown',26); Query OK, 1 row affected (0.00 sec)
使用 select 语句从表中显示所有记录 -
mysql> select * from DemoTable1903;
这将产生以下输出 -
+-----------+----------+------+ | FirstName | LastName | Age | +-----------+----------+------+ | John | Smith | 23 | | None | Miller | 28 | | None | Taylor | 26 | | Chris | Brown | 26 | +-----------+----------+------+ 4 rows in set (0.00 sec)
以下是更新列名并使用 N/A 设置 NONE 的查询 -
mysql> update DemoTable1903 set FirstName='N/A' where FirstName='None'; Query OK, 2 rows affected (0.00 sec) Rows matched: 2 Changed: 2 Warnings: 0
让我们再次检查一下表记录 -
mysql> select * from DemoTable1903;
这将产生以下输出 -
+-----------+----------+------+ | FirstName | LastName | Age | +-----------+----------+------+ | John | Smith | 23 | | N/A | Miller | 28 | | N/A | Taylor | 26 | | Chris | Brown | 26 | +-----------+----------+------+ 4 rows in set (0.00 sec)
广告