How do I show the schema of a table in a MySQL database?


To show the schema, we can use the DESC command. This gives the description about the table structure.

The following is the syntax.

DESCRIBE yourDatabasename.yourTableName;

Let us implement the above syntax.

mysql> DESCRIBE business.student;

The following is the output.

+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id    | int(11)      | YES  | MUL | NULL    |       |
| Name  | varchar(100) | YES  | MUL | NULL    |       |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.05 sec)

Syntax to show the schema of a table with the help of show create table command.

show create table yourDatabasename.yourTableName;

The following is the query.

mysql> show create table business.student;

Here is the output displaying the schema.

+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table  | Create Table                                                                                                                                                                                                                                  |
+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| student | CREATE TABLE `student` (`id` int(11) DEFAULT NULL,
   `Name` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
   KEY `NameStuIndex` (`Name`),
   KEY `idIndex` (`id`)
)  ENGINE = InnoDB 
   DEFAULT CHARSET = utf8mb4 
   COLLATE =                                                                                                                                                                                                                                              |
+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.03 sec)

Updated on: 01-Sep-2023

86K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements