Tutorialspoint

1 Answer
Rama Giri

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;

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';

This will produce the following output −

+------------+
| TABLE_ROWS |
+------------+
|          4 |
+------------+
1 row in set (0.16 sec)

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.