Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Get the number of rows in a particular table with MySQL
Let us first create a table −
mysql> create table DemoTable -> ( -> LastName varchar(100) -> ); Query OK, 0 rows affected (0.68 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Smith');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable values('Miller');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable values('Taylor');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values('Brown');
Query OK, 1 row affected (0.29 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+----------+ | LastName | +----------+ | Smith | | Miller | | Taylor | | Brown | +----------+ 4 rows in set (0.00 sec)
Following is the query to get the number of rows in a particular table in the database “web” −
mysql> select table_rows from INFORMATION_SCHEMA.tables -> where table_schema='web' and table_name='DemoTable';
Output
This will produce the following output −
+------------+ | TABLE_ROWS | +------------+ | 4 | +------------+ 1 row in set (0.16 sec)
Advertisements
