更新 MySQL 中特定单元格的内容
让我们首先创建一个表格 −
mysql> create table DemoTable2029 -> ( -> Id int, -> FirstName varchar(20), -> LastName varchar(20) -> ); Query OK, 0 rows affected (0.98 sec)
使用 insert 命令在表格中插入一些记录 −
mysql> insert into DemoTable2029 values(1,'Chris','Brown') -> ; Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2029 values(2,'David','Miller'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2029 values(3,'John','Smith'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable2029 values(4,'John','Brown'); Query OK, 1 row affected (0.27 sec)
使用 select 语句显示表格中的所有记录 −
mysql> select *from DemoTable2029;
这将生成以下输出 −
+------+-----------+----------+ | Id | FirstName | LastName | +------+-----------+----------+ | 1 | Chris | Brown | | 2 | David | Miller | | 3 | John | Smith | | 4 | John | Brown | +------+-----------+----------+ 4 rows in set (0.00 sec)
以下是更新特定单元格的查询 −
mysql> update DemoTable2029 -> set FirstName='Adam',LastName='Smith' -> where Id=4; Query OK, 1 row affected (0.14 sec) Rows matched: 1 Changed: 1 Warnings: 0
让我们再次检查表格记录 −
mysql> select *from DemoTable2029;
这将生成以下输出 −
+------+-----------+----------+ | Id | FirstName | LastName | +------+-----------+----------+ | 1 | Chris | Brown | | 2 | David | Miller | | 3 | John | Smith | | 4 | Adam | Smith | +------+-----------+----------+ 4 rows in set (0.00 sec)
广告