

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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?
<p>To display number of fields in MySQL, use the COUNT(*). Following is the syntax −</p><pre class="result notranslate">select COUNT(*) AS anyAliasName from INFORMATION_SCHEMA.COLUMNS where table_name = yourTableName AND TABLE_SCHEMA = yourDatabaseName;</pre><p>Let us first create a table −</p><pre class="result notranslate">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)</pre><p>Following is the query to get the number of fields in MySQL −</p><pre class="prettyprint notranslate">mysql> select COUNT(*) AS TOTAL_NUMBER_OF_COLUMNS from INFORMATION_SCHEMA.COLUMNS where table_name = 'DemoTable794' AND TABLE_SCHEMA = 'web';</pre><p>This will produce the following output -</p><pre class="result notranslate">+-------------------------+ | TOTAL_NUMBER_OF_COLUMNS | +-------------------------+ | 4 | +-------------------------+ 1 row in set (0.00 sec)</pre>
- Related Questions & Answers
- Get the count of two table fields in a single MySQL query?
- Display all fields of a table in MySQL?
- Get the number of columns in a MySQL table?
- Get the number of rows in a particular table with MySQL
- Easiest way to get number of rows in a MySQL table?
- Get the fields in each constraint in MySQL
- How to get number of rows in a table without using count(*) MySQL query?
- Count number of rows in each table in MySQL?
- How to apply Substring() for fields in MySQL to get part of string?
- Get number of users of different type in MySQL?
- Get Last Entry in a MySQL table?
- How to get primary key of a table in MySQL?
- Get the second last row of a table in MySQL?
- How to get the datatype of MySQL table columns?
- Get the average row length of a MySQL table
Advertisements