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)