Skip to main content

DESCRIBE

Description​

This statement is used to display the schema information of the specified table.

Syntax​

DESC[RIBE] [db_name.]table_name [ALL];

Required Parameters​

1.<table_name>

Specifies the table identifier (name), which must be unique within the database in which it is located.

Identifiers must begin with an alphabetic character (or any character in a language if unicode name support is enabled) and cannot contain spaces or special characters unless the entire identifier string is enclosed in backticks (e.g. My Object).

Identifiers cannot use reserved keywords.

For more details, see Identifier Requirements and Reserved Keywords.

Optional Parameters​

1.<db_name>

Specifies the identifier (i.e., name) for the database.

Identifiers must begin with an alphabetic character (or any character in a given language if unicode name support is enabled) and cannot contain spaces or special characters unless the entire identifier string is enclosed in backticks (e.g., My Database).

Identifiers cannot use reserved keywords.

See Identifier Requirements and Reserved Keywords for more details.

2.RIBE

Returns description information of all columns in a table

3.ALL

Returns description information for all columns

Return Value​

column namedescription
IndexNameTable name
IndexKeysTypeTable Model
FieldColumn Name
TypeData Types
NullWhether NULL values are allowed
KeyIs it a key column
DefaultDefault Value
ExtraDisplay some additional information
VisibleVisible
DefineExprDefining Expressions
WhereClauseFilter Conditions Related Definitions

Access Control Requirements​

Users executing this SQL command must have at least the following privileges:

PrivilegeObjectNotes
SELECT_PRIVTableWhen executing DESC, you need to have the SELECT_PRIV privilege on the table being queried

Usage Notes​

  • If ALL is specified, the schema of all indexes (rollup) of the table is displayed.

Examples​

  1. Display the Base table schema
DESC test_table;
+---------+-------------+------+-------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-------+---------+-------+
| user_id | bigint | No | true | NULL | |
| name | varchar(20) | Yes | false | NULL | NONE |
| age | int | Yes | false | NULL | NONE |
+---------+-------------+------+-------+---------+-------+
  1. Display the schema of all indexes in the table
DESC demo.test_table ALL;
+------------+---------------+---------+-------------+--------------+------+-------+---------+-------+---------+------------+-------------+
| IndexName | IndexKeysType | Field | Type | InternalType | Null | Key | Default | Extra | Visible | DefineExpr | WhereClause |
+------------+---------------+---------+-------------+--------------+------+-------+---------+-------+---------+------------+-------------+
| test_table | DUP_KEYS | user_id | bigint | bigint | No | true | NULL | | true | | |
| | | name | varchar(20) | varchar(20) | Yes | false | NULL | NONE | true | | |
| | | age | int | int | Yes | false | NULL | NONE | true | | |
+------------+---------------+---------+-------------+--------------+------+-------+---------+-------+---------+------------+-------------+