
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to get field name types from a MySQL database?
You can use INFORMATION_SCHEMA.COLUMNS for this. Following is the syntax −
SELECT COLUMN_NAME,COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='yourTableName';
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(60), ClientAge int, ClientSalary DECIMAL(10,4), isRegularClient bool ); Query OK, 0 rows affected (0.44 sec)
Following is the query to get field name types from a SQL database −
mysql> SELECT COLUMN_NAME,COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='DemoTable';
This will produce the following output −
+-----------------+---------------+ | COLUMN_NAME | COLUMN_TYPE | +-----------------+---------------+ | Id | int(11) | | ClientName | varchar(60) | | ClientAge | int(11) | | ClientSalary | decimal(10,4) | | isRegularClient | tinyint(1) | +-----------------+---------------+ 5 rows in set (0.02 sec)
- Related Articles
- How to remove special characters from a database field in MySQL?
- Get database name from a query implemented in a MySQL Stored Procedure?
- How to get an age from a D.O.B field in MySQL?
- Get a list of Constraints from MySQL Database?
- How to get day name from timestamp in MySQL?
- How to get ER model of database from server with MySQL Workbench?
- How to get username using ID from another table in MySQL database?
- MySQL increment a database field by 1?
- How to get MySQL combined field result?
- How can we see only name and types of the stored routines in a particular MySQL database?
- How to derive value of a field from another field in MySQL?
- How to select a random record from a MySQL database?
- How to select first 10 elements from a MySQL database?
- How to retrieve table names from a database in MySQL?
- MySQL database field type for search query?

Advertisements