- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get field name types from a MySQL database?
152 Lectures 16 hours
87 Lectures 5.5 hours
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)
- Get database name from a query implemented in a MySQL Stored Procedure?
- How to remove special characters from a database field in MySQL?
- How to get an age from a D.O.B field in MySQL?
- How to get day name from timestamp in MySQL?
- Get a list of Constraints from MySQL Database?
- MySQL increment a database field by 1?
- How can we see only name and types of the stored routines in a particular MySQL database?
- How to get MySQL combined field result?
- Get Month Name from Month number in MySQL?
- How to derive value of a field from another field 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?
- How to get file name from a path in PHP?
- How to select a random record from a MySQL database?
- Get employee name from a specific company using MySQL GROUP BY?