让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(Name) values('Carol'); mysql> insert into DemoTable(Name) values('Chris'); mysql> insert into DemoTable(Name) values('David'); mysql> insert into DemoTable(Name) values('Bob'); mysql> insert into DemoTable(Name) values('Mike'); mysql> insert into DemoTable(Name) values('Sam'); mysql> insert into DemoTable(Name) values('Robert'); mysql> insert into DemoTable(Name) values('Adam');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+----+--------+ | Id | Name | +----+--------+ | 1 | Carol | | 2 | Chris | | 3 | David | | 4 | Bob | | 5 | Mike | | 6 | Sam | | 7 | Robert | | 8 | Adam | +----+--------+ 8 rows in set (0.00 sec)
这是查询以更新表并设置具有相同值的列,但最后一列值除外-
mysql> update DemoTable -> set Name="John" -> limit 7; Rows matched: 7 Changed: 7 Warnings: 0
让我们再次检查表记录。
mysql> select *from DemoTable;
输出结果
+----+------+ | Id | Name | +----+------+ | 1 | John | | 2 | John | | 3 | John | | 4 | John | | 5 | John | | 6 | John | | 7 | John | | 8 | Adam | +----+------+ 8 rows in set (0.00 sec)