让我们首先创建一个表-
mysql> create table DemoTable ( Name varchar(40), Position int );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('Chris',90); mysql> insert into DemoTable values('David',67); mysql> insert into DemoTable values('Bob',55); mysql> insert into DemoTable values('Sam',40);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-------+----------+ | Name | Position | +-------+----------+ | Chris | 90 | | David | 67 | | Bob | 55 | | Sam | 40 | +-------+----------+ 4 rows in set (0.00 sec)
以下是仅更新范围中的特定记录而不更新整个列的查询-
mysql> update DemoTable set Position=Position+10 where Position > 50 and Position < 90; Rows matched : 2 Changed : 2 Warnings : 0
让我们再次检查表记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-------+----------+ | Name | Position | +-------+----------+ | Chris | 90 | | David | 77 | | Bob | 65 | | Sam | 40 | +-------+----------+ 4 rows in set (0.00 sec)