
MySQL Describe Table
To describe a table in MySQL, you can use the DESCRIBE
or DESC
statement. These statements provide information about the structure of a table, including the column names, data types, and any constraints. Here’s the basic syntax:
DESCRIBE table_name;
or
DESC table_name;
table_name
: The name of the table you want to describe.
For example, to describe the structure of a table named “students,” you would use the following SQL statement:
DESCRIBE students;
or
DESC students;
Upon executing this command, MySQL will return a result set with information about the table’s columns, including the column name, data type, whether it allows null values, the default value, and any additional information such as the auto-increment property.
Here’s an example of what the output might look like:
+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| student_id | int(11) | NO | PRI | NULL | auto_increment |
| first_name | varchar(50) | YES | | NULL | |
| last_name | varchar(50) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
+------------+-------------+------+-----+---------+----------------+
In this example, the table “students” has four columns, each with its data type, nullability, and other information.
The DESCRIBE
or DESC
statement is a valuable tool for understanding the structure of a table, particularly when working with an unfamiliar database or when you need to verify the columns and their characteristics for use in your queries and applications.