让我们首先创建一个表-
mysql> create table DemoTable ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(40), ClientAge int, ClientCountryName varchar(40) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(ClientName,ClientAge,ClientCountryName) values('Chris',25,'US'); mysql> insert into DemoTable(ClientName,ClientAge,ClientCountryName) values('Bob',55,'UK'); mysql> insert into DemoTable(ClientName,ClientAge,ClientCountryName) values('David',45,'AUS');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----------+------------+-----------+-------------------+ | ClientId | ClientName | ClientAge | ClientCountryName | +----------+------------+-----------+-------------------+ | 1 | Chris | 25 | US | | 2 | Bob | 55 | UK | | 3 | David | 45 | AUS | +----------+------------+-----------+-------------------+ 3 rows in set (0.00 sec)
这是将MySQL表的所有列设置为特定值的查询-
mysql> update DemoTable set ClientName='Sam',ClientAge=48,ClientCountryName='AUS' where ClientId=2; Rows matched : 1 Changed : 1 Warnings : 0
让我们再次检查表记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----------+------------+-----------+-------------------+ | ClientId | ClientName | ClientAge | ClientCountryName | +----------+------------+-----------+-------------------+ | 1 | Chris | 25 | US | | 2 | Sam | 48 | AUS | | 3 | David | 45 | AUS | +----------+------------+-----------+-------------------+ 3 rows in set (0.00 sec)