让我们首先来看一个创建表,添加记录并显示它们的示例。CREATE命令用于创建表。mysql> CREATE table RowCountDemo
-> (
-> ID int,
-> Name varchar(100)
> );
使用INSERT命令插入记录。mysql>INSERT into RowCountDemo values(1,'Larry');
mysql>INSERT into RowCountDemo values(2,'John');
mysql>INSERT into RowCountDemo values(3,'Bela');
mysql>INSERT into RowCountDemo values(4,'Jack');
mysql>INSERT into RowCountDemo values(5,'Eric');
mysql>INSERT into RowCountDemo values(6,'Rami');
mysql>INSERT into RowCountDemo values(7,'Sam');
mysql>INSERT into RowCountDemo values(8,'Maike');
mysql>INSERT into RowCountDemo values(9,'Rocio');
mysql>INSERT into RowCountDemo values(10,'Gavin');
显示记录。mysql>SELECT *from RowCountDemo;
以下是上述查询的输出。+------+-------+
| ID | Name |
+------+-------+
| 1 | Larry |
| 2 | John |
| 3 | Bela |
| 4 | Jack |
| 5 | Eric |
| 6 | Rami |
| 7 | Sam |
| 8 | Maike |
| 9 | Rocio |
| 10 | Gavin |
+------+-------+
10 rows in set (0.00 sec)
为了快速计算行数,我们有以下两个选项-
查询1mysql >SELECT count(*) from RowCountDemo;
以下是上述查询的输出。+----------+
| count(*) |
+----------+
| 10 |
+----------+
1 row in set (0.00 sec)
查询2mysql>SELECT count(found_rows()) from RowCountDemo;
以下是上述查询的输出。+---------------------+
| count(found_rows()) |
+---------------------+
| 10 |
+---------------------+
1 row in set (0.00 sec)