SQL Tutorial
SQL Clauses / Operators
SQL-Injection
SQL Functions
SQL Queries
PL/SQL
MySQL
SQL Server
Misc
The DESCRIBE
statement (often abbreviated as DESC
) is used in SQL to retrieve metadata about a specified table or view. It provides details like column names, data types, whether a column can be NULL, and other attributes of the table. This command is particularly useful when you want to examine the structure of a table.
However, the availability and exact syntax of the DESCRIBE
statement can vary between different relational database management systems (RDBMS). Here are some examples for popular RDBMS:
DESCRIBE table_name;
or simply:
DESC table_name;
SQL Server does not have a DESCRIBE
statement. Instead, you'd typically use the sp_help
stored procedure or query the INFORMATION_SCHEMA.COLUMNS
system view.
EXEC sp_help table_name;
or
SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'table_name';
PostgreSQL doesn't have a DESCRIBE
statement either. Instead, you can use the \d
command in the psql
command-line tool:
\d table_name
Alternatively, you can query the information_schema
or pg_catalog
schema to get details about tables and columns.
In SQLite, the .schema
command is used to see the creation SQL for a specific table:
.schema table_name
The result will be the CREATE TABLE
statement used to define the table, which includes column names, data types, and other constraints.
When working with an RDBMS, it's essential to know how to inspect the structure of a table, especially when dealing with unfamiliar databases. The method you use to achieve this will depend on the RDBMS in question, so always consult the relevant documentation if unsure.
How to Use DESCRIBE in Oracle:
DESCRIBE employees;
DESCRIBE Command in Oracle SQL:
DESCRIBE employees;
View Table Structure in Oracle SQL:
DESCRIBE employees;
Oracle DESCRIBE Statement for Columns:
DESCRIBE employees;
DESCRIBE TABLE in Oracle SQL:
DESCRIBE employees;
Get Information About a Table in Oracle:
DESCRIBE employees;
DESCRIBE Statement Alternatives in Oracle:
SELECT COLUMN_NAME, DATA_TYPE FROM USER_TAB_COLUMNS WHERE TABLE_NAME = 'EMPLOYEES';
SELECT * FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = 'EMPLOYEES';
Exploring Table Structure with DESCRIBE in Oracle:
DESCRIBE employees;
Using DESCRIBE in MySQL:
DESCRIBE employees;
SHOW COLUMNS FROM in MySQL:
SHOW COLUMNS FROM employees;
View Table Structure in MySQL:
SHOW COLUMNS FROM employees;
Get Information About a Table in MySQL:
SHOW COLUMNS FROM employees;
MySQL SHOW COLUMNS FROM Statement:
SHOW COLUMNS FROM employees;
MySQL DESCRIBE vs. SHOW COLUMNS FROM:
DESCRIBE employees; SHOW COLUMNS FROM employees;
Exploring Table Structure in MySQL:
SHOW COLUMNS FROM employees;
Retrieve Column Details in MySQL:
SHOW COLUMNS FROM employees;