English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

MySQL 테이블의 행 수를 계산하는 가장 빠른 방법?

먼저 테이블을 생성하고, 레코드를 추가하여 표시하는 예제를 보겠습니다. 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)

행 수를 빠르게 계산하기 위해 다음 두 가지 옵션이 있습니다-

조회1

mysql >SELECT count(*) from RowCountDemo;

이상의 쿼리의 출력은 다음과 같습니다.

+----------+
| count(*) |
+----------+
| 10       |
+----------+
1 row in set (0.00 sec)

조회2

mysql>SELECT count(found_rows()) from RowCountDemo;

이상의 쿼리의 출력은 다음과 같습니다.

+---------------------+
| count(found_rows()) |
+---------------------+
| 10                  |
+---------------------+
1 row in set (0.00 sec)
추천해드립니다