Data Query Language
DQL(Data Query Language) is used to extract data from a database. Lets discuss few DQL statements.
SELECT statement
It is used to select data from a table.
SELECT column1, column2,... FROM table_name;
SELECT DISTINCT statement
It is used to select distinct data values from a table. It doesn't repeat duplicate values.
SELECT DISTINCT column1, column2,... FROM table_name;
SHOW statements
It is used to show different information about databases, tables and columns. Some frequently used show commands are as follows:
-
SHOW DATABASES
It is used to list available databases.
SHOW DATABASES;
-
SHOW TABLES
It is used to list available tables.
SHOW TABLES;
-
SHOW COLUMNS
It will show all the columns and its details for a specified table.
SHOW columns FROM table_name;
Here column is a pre-defined word. table_name is actually the name of your table.
How to get the data type of columns using SQL Query?
This is how you can get datatypes of various columns in a table.
SELECT column_name, data_type, character_maximum_length FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'table_name' and TABLE_SCHEMA='database_name';