How to use INFORMATION_SCHEMA.COLUMNS Table In MariaDB
The INFORMATION_SCHEMA.COLUMNS statement allows you to get information about all columns within all tables and view in the database. You can use the SELECT statement to get columns such as TABLE_CATALOG, TABLE_NAME, COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_KEY etc and use the WHERE statement to get results of a specific database and table with additional conditions that you prefer.
Syntax:
SELECT COLUMN_NAME, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'database_name'
AND TABLE_NAME = 'table_name';
Example: Retrieving the data type using INFORMATION_SCHEMA.COLUMNS Table
The below query uses INFORMATION_SCHEMA.COLUMNS to get the column_name, data_type column of table customers.
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'customers';
Output:
Explanation: The query displays the details of all the columns of the customers table. The result includes the table name, all the columns of the table and respective data type of the columns.
How to Get the Data Type of a Columns in MariaDB
When it comes to managing databases, understanding the types of data stored in each column is crucial. In MariaDB, this knowledge not only helps in organizing data efficiently but also enables more effective querying and analysis.
In this article, we’ll explore How to Get the Data Type of Columns in MariaDB with simple but powerful methods to retrieve column data types in MariaDB.