Syntax error Total number of fields in all tables in database?\\n

Total number of fields in all tables in database?\\n



To get total number of fields in all tables in database, you can use information_schema.columns along with aggregate function count(*).

We are using ‘sample’ database which consists of a lot of tables with fields. Following is the query to get total number of fields in all tables in database:

mysql> SELECT COUNT(*) AS TOTAL_NUMBER_OF_FIELDS
   -> FROM INFORMATION_SCHEMA.COLUMNS
   -> WHERE TABLE_SCHEMA = 'sample';

This will produce the following output

+------------------------+
| TOTAL_NUMBER_OF_FIELDS |
+------------------------+
| 796                    |
+------------------------+
1 row in set (0.04 sec)

Now, let us check another database ‘test’. Following is the query to get total number of fields in all tables in database:

mysql> SELECT COUNT(*) AS TOTAL_NUMBER_OF_FIELDS
   -> FROM INFORMATION_SCHEMA.COLUMNS
   -> WHERE TABLE_SCHEMA= 'test';

This will produce the following output

+------------------------+
| TOTAL_NUMBER_OF_FIELDS |
+------------------------+
| 1108                   |
+------------------------+
1 row in set (0.03 sec)
Updated on: 2019-07-30T22:30:25+05:30

771 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements