为此,您只需要使用一次SET命令。让我们首先创建一个表-
mysql> create table DemoTable1909 ( Id int NOT NULL, FirstName varchar(20), LastName varchar(20) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1909 values(101,'John','Smith'); mysql> insert into DemoTable1909 values(102,'John','Doe'); mysql> insert into DemoTable1909 values(103,'Adam','Smith'); mysql> insert into DemoTable1909 values(104,'David','Miller');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1909;
这将产生以下输出-
+-----+-----------+----------+ | Id | FirstName | LastName | +-----+-----------+----------+ | 101 | John | Smith | | 102 | John | Doe | | 103 | Adam | Smith | | 104 | David | Miller | +-----+-----------+----------+ 4 rows in set (0.00 sec)
这是更新两个列值的查询-
mysql> update DemoTable1909 set FirstName='Carol',LastName='Taylor' where Id=103; Rows matched: 1 Changed: 1 Warnings: 0
让我们再次检查表记录-
mysql> select * from DemoTable1909;
这将产生以下输出-
+-----+-----------+----------+ | Id | FirstName | LastName | +-----+-----------+----------+ | 101 | John | Smith | | 102 | John | Doe | | 103 | Carol | Taylor | | 104 | David | Miller | +-----+-----------+----------+ 4 rows in set (0.00 sec)