让我们首先创建一个表-
create table DemoTable -> ( -> Id int, -> Name varchar(20), -> Age int, -> CountryName varchar(10) -> );
使用插入命令在表中插入一些记录-
insert into DemoTable values(100,'Chris',34,'AUS'); insert into DemoTable values(101,'Chris',31,'US'); insert into DemoTable values(102,'David',25,'UK'); insert into DemoTable values(103,'Carol',28,'AUS');
使用select语句显示表中的所有记录-
select * from DemoTable;
这将产生以下输出-
+------+-------+------+-------------+ | Id | Name | Age | CountryName | +------+-------+------+-------------+ | 100 | Chris | 34 | AUS | | 101 | Chris | 31 | US | | 102 | David | 25 | UK | | 103 | Carol | 28 | AUS | +------+-------+------+-------------+ 4 rows in set (0.00 sec)
这是使用WHERE子句中的多个值更新的查询-
update DemoTable -> set Name='Robert' -> where Age=31 and CountryName='US'; Rows matched: 1 Changed: 1 Warnings: 0
让我们再次检查表记录-
select * from DemoTable;
这将产生以下输出-
+------+--------+------+-------------+ | Id | Name | Age | CountryName | +------+--------+------+-------------+ | 100 | Chris | 34 | AUS | | 101 | Robert | 31 | US | | 102 | David | 25 | UK | | 103 | Carol | 28 | AUS | +------+--------+------+-------------+ 4 rows in set (0.00 sec)