
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Number of Fields in MySQL Table
To display number of fields in MySQL, use the COUNT(*). Following is the syntax −
select COUNT(*) AS anyAliasName from INFORMATION_SCHEMA.COLUMNS where table_name = yourTableName AND TABLE_SCHEMA = yourDatabaseName;
Let us first create a table −
mysql> create table DemoTable794 ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(100), ClientAge int, ClientCountryName varchar(100) ); Query OK, 0 rows affected (1.61 sec)
Following is the query to get the number of fields in MySQL −
mysql> select COUNT(*) AS TOTAL_NUMBER_OF_COLUMNS from INFORMATION_SCHEMA.COLUMNS where table_name = 'DemoTable794' AND TABLE_SCHEMA = 'web';
This will produce the following output -
+-------------------------+ | TOTAL_NUMBER_OF_COLUMNS | +-------------------------+ | 4 | +-------------------------+ 1 row in set (0.00 sec)
Advertisements