The Wayback Machine - https://web.archive.org/web/20241106123700/https://www.geeksforgeeks.org/mysql-describe-table/
Open In App

MySQL Describe Table

Last Updated : 17 Jun, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

MySQL is an open-source relational database management system (RDBMS). It is one of the most popular databases globally, known for its reliability, and scalability. MySQL is designed to run on various operating systems, including Windows, Linux, macOS, and more. It is known for its high performance, quick retrieval, and efficient storage.

It provides robust security features, including user authentication, access control, and data encryption. In this article, we will understand how to use the DESCRIBE TABLE command using steps to follow, examples, and so on.

DESCRIBE TABLE in MYSQL

The DESCRIBE TABLE statement, also commonly written as DESC TABLE or DESCRIBE, is a MySQL command used to retrieve metadata about a table. It offers a better way to view essential information about the columns within a specified table, such as the data type, nullability, and key constraints. DESCRIBE TABLE displays information about primary and foreign key constraints, providing insights into the relationships between tables.

Understanding the structure of databases is important for good database handling and development. In MySQL, the­ DESCRIBE TABLE command is helpful. It gives us detailed info about a table's structure and attributes.

How To Describe a Table In MySQL?

The DESCRIBE TABLE command in MySQL is a use­ful Data Definition Language (DDL) command. It's good for inspecting the structure of a table. It shows users about columns, data types, constraints, and other attributes. It give­s an overall look at how the table­ is structured. To understand the DESCRIBE TABLE in MYSQL we should know SQL Data Types, SQL Types of Indexes, and SQL Types of Keys.

Steps for Executing DESCRIBE Statement

Executing the­ DESCRIBE TABLE statement is simple. First, ope­n a MySQL command-line interface or a database­ management tool(WorkBench).

Then, run the following command:

DESCRIBE table_name;

Explanation: This command will return a result containing information about the specified table.

The output of the DESCRIBE statement includes columns like:

  • Field: the column name.
  • Type the data type of the column.
  • Null: whether the column allows NULL values or not.
  • Key: index information of the column.
  • Default: the default value set in the column.
  • Extrathe: additional information about the column.

How to Display Table Information in MySQL Workbench?

In MySQL Workbench, you can view table information by:

  • Open MySQL Workbench and connect to the database.
  • In the Navigator(that left side panel), locate and expand that database.
  • Click on "Tables".
  • Right-click on the table you want to describe.
  • Click on "Table Inspector" to view detailed information.

Let's see the visual representation of How to Display Table Information in MySQL Workbench

Example of DESCRIBE TABLE

We have two tables named student, fees with some columns.

Let's perform the DESCRIBE TABLE command in the student table and understand the output.

Query:

DESCRIBE students;

Output:

MyqlDescribeTable1
Describing student table

Explanation:

Let's understand the output of each column in the table, including its data type, nullability, constraints, and default values:

  • student_id: This is shown as type int. The NO shows it cannot be NULL. As a primary key (PRI). As Extra its have auto_increment for autoge­nerated integer.
  • first_name This is a varchar(50) column, it can be­ up to 50 characters in length. The NO shows it cannot be NULL.
  • last_name: same as per the first_name column.
  • date_of_birth: This column is of type of date. The NULL field is marked as YES, meaning it allows NULL values.
  • email : A varchar(100) type­ column, it can be­ up to 100 characters in length. The NULL field is marked as YES, meaning it stores NULL values. The UNI key shows it has a unique constraint.
  • Registration_date: This is a timestamp column. It can have NULL values. The CURRENT_TIMESTAMP and DEFAULT_GENERATED set automatically default values using the current timestamp when we add a new row.
  • is_active: This column is of type tinyint(1), it allows NULL values, and the default value is 1.

Let's perform the DESCRIBE TABLE command in the fees table and understand the output.

Query:

DESCRIBE fees

Output:

MyqlDescribeTable2
Describing fees table

Explanation:

  • fee_id: This column is a type of int. The NULL value field is NO, so it can't be empty. As a primary key (PRI). As Extra its have auto_increment for autoge­nerated integer.
    stores
  • student_id: This column is of type int. It stores NULL values. MUL means it's part of multiple indexes. This column has a foreign key referencing to the student_id in the student table.
  • amount: This column is a type of decimal. It can have up to 8 digits in total, 2 being after the dot. The NULL value field is NO, so it can't be empty.
  • payment_date: This column is a type of date. It stores NULL values. MUL means it’s part of multiple indexes.

MySQL SHOW COLUMNS Command

Another way to get table information is using the SHOW COLUMNS command.

Query:

SHOW COLUMNS FROM student;

This command gives details similar to the DESCRIBE statement.

Both "SHOW COLUMNS FROM student" and "DESCRIBE stude­nt" provide details on the "student" table­ but in different ways. "SHOW COLUMNS FROM student" pre­sents details in table form. It shows the fie­ld name, and data type if it allows null, key, de­fault value, and more. Alternative­ly, "DESCRIBE student" offers a simple list. This simple list may not show relevant info, unlike "SHOW COLUMNS." There­fore, it's up to the user to se­lect either a de­tailed table or a simple list. But, in most cases, both commands will show similar results.

Conclusion

MySQL table structure knowledge is good for database handling. You can understand it using commands like DESCRIBE, and SHOW COLUMNS, and tools like MySQL Workbench. This will show you table parts like column names, data types, and constraints. This article shows easy instructions for these commands. It helps make managing data more efficient.

FAQs on MySQL DESCRIBE Table

What is the purpose of the DESCRIBE statement in MySQL?

The DESCRIBE statement is used to display the structure of a table, including details about each column such as its name, data type, nullability, key constraints, default values, and extra attributes like auto_increment.

How do you use the DESCRIBE command to view a table's structure?

To view a table's structure, use the command DESCRIBE table_name;, replacing table_name with the name of your table. You can also use EXPLAIN table_name; or and expand that databaseto get the same information.

What do the PRI, UNI, and MUL values in the Key column indicate?

  • PRI: The column is part of the primary key, which uniquely identifies each row.
  • UNI: The column has a unique constraint, ensuring all values are unique.
  • MUL: The column is part of a non-unique index, allowing multiple occurrences of the same value.

Similar Reads

SQLite Describe Table
SQLite is an embedded database that doesn't use a database like Oracle in the background to operate. It is written in C language and is used by developers who embed a lightweight database over the existing application, browser, or embedded systems. SQLite works on various platforms like Windows, Mac, Linux, iOS and Android. This makes popular choic
8 min read
SQL Server Describe Table
SQL Server is a widely used Relational Database Management System (RDBMS) that allows users to create and manage databases effectively. When working with databases in SQL Server it is essential to understand the schema of the tables present in the database. Describing a table means getting information about the structure and metadata of the table.
4 min read
Update One Table with Another Table's Values in MySQL
Sometimes we need to update a table data with the values from another table in MySQL. Doing this helps in efficiently updating tables while also maintaining the integrity of the database. This is mostly used for automated updates on tables. We can update values in one table with values in another table, using an ID match. ID match ensures that the
3 min read
Functions in MySQL | Numeric, String and Date Time Functions in MySQL
In MySQL, functions play a crucial role in performing various operations on data, such as calculations, string manipulations, and date handling. These built-in functions simplify complex queries and data transformations, making it easier to manage and analyze data within a database. In this article, we will look at these different categories of MyS
4 min read
MySQL Can't Specify Target Table For Update in FROM Clause
The "MySQL can't specify target table for update in FROM clause" error is a common challenge encountered when attempting to update a table based on a subquery that refers to the same table in the FROM clause. This restriction is in place to prevent ambiguous or unintended updates that might arise from self-referencing subqueries. So, in this articl
3 min read
How to Find Records From One Table Which Don't Exist in Another MySQL
MySQL is a free and open-source relational database management system written in C and C++ that is extremely popular among developers. Like other relational database management systems, MySQL provides a variety of rich features to create databases and tables, insert data in them, and further manipulate them as the system evolves. In this article, w
5 min read
MySQL CREATE TABLE
Creating tables in MySQL is a fundamental task for organizing and managing data within a database. Tables act as structured containers, similar to spreadsheets, where data is stored in rows and columns. In this article, we will explore the process of creating tables in MySQL using both the Command Line Interface (CLI) and MySQL Workbench. MySQL CRE
4 min read
How to Return Pivot Table Output in MySQL
Pivoting a table in MySQL involves transforming rows into columns, which can be particularly useful for data analysis and reporting. While MySQL does not have a native PIVOT function like some other database systems, you can achieve pivoting using conditional aggregation with the CASE statement. So, In this article, we will explore how can I return
5 min read
MySQL RENAME TABLE Statement
The MySQL RENAME TABLE statement is a simple yet powerful command that allows you to change the name of an existing table in your database. This can be useful for various reasons, such as updating table names to better reflect their content or restructuring your database without losing any data. By using RENAME TABLE, you can easily and quickly ren
5 min read
MySQL DROP TABLE Statement
MySQL is a free and open-source relational database management system written in C and C++ that is extremely popular among developers. Like other relational database management systems, MySQL provides various rich features to create databases and tables, insert data in them, and further manipulate them as the system evolves. In this article, we are
6 min read
How to Get the Datatype of Table Columns in MySQL?
When working with MySQL databases, knowing the datatype of table columns is essential to maintain data integrity and avoid errors. This guide covers methods to check column datatypes, such as using SHOW COLUMNS and querying INFORMATION_SCHEMA.COLUMNS. Understanding column datatypes helps in designing databases, ensuring data validation, and optimiz
4 min read
How to Update Table Rows Using Subquery in MySQL
Updating table rows using subqueries in MySQL enables precise modifications based on specific conditions or values from other tables. This technique leverages subqueries within the SET or WHERE clauses of the UPDATE statement, allowing dynamic and context-specific updates. This guide covers the syntax, methods, and examples of updating rows with ag
5 min read
MySQL Temporary Table
Do you want to store the intermediate results of your query in some table but only for a given DB session and not persist for the lifetime? Is there some way to hold temporary data for a short time without making it permanent on the database forever? If you have ever thought about this and wondered how to do that, then you have arrived at the right
5 min read
Introduction to MySQL Table Partitioning
The MySQL table partitioning feature divides large tables into smaller, more manageable partitions. Each partition can be thought of as a separate sub-table with its own storage engine, indexes, and data. Partitioning is particularly useful for improving query performance reducing the index size and enhancing data management in scenarios where tabl
6 min read
MySQL REPAIR TABLE
MySQL is an open-source Relational Database Management system that stores the data in the form of rows and columns and SQL is the language that is used to store, manipulate, and retrieve the data. "REPAIR TABLE" is one of the useful commands in MySQL and is used for repairing the tables in case the tables get corrupted. The corruption of the tables
5 min read
MySQL Derived Table
Structured Query Language (SQL) is a powerful tool for managing and querying relational databases, and MySQL is one of the most widely used database management systems. In MySQL, derived tables offer a flexible and efficient way to manipulate and analyze data within a query. In this article, we will get inside the concept of MySQL-derived tables, e
5 min read
MySQL Common Table Expressions
One of the most powerful features added in MySQL version 8.0 is common table expressions, which allow for the construction of temporary result sets within a single SQL query. In our daily life queries, we often use common table expressions and it makes our work easier. In this article, we will understand the Common Table Expression with examples an
6 min read
Cloning Table in MySQL
Duplicating a table in MySQL involves creating a new table that replicates an existing table's structure and/or data. This capability is valuable for creating backups, setting up test environments, or transferring data between databases. In this article, we will explore various methods for duplicating tables in MySQL, including copying only the tab
3 min read
MySQL - CHECKSUM TABLE Statement
The CHECKSUM TABLE statement in MySQL is a useful tool to verify the integrity of tables and detect any changes or corruption in the data stored within them. This statement calculates a checksum value for a table and its contents, allowing users to compare the results across backups, replicas, or after operations that may modify the data. In this a
5 min read
How to Update a Table Data From Another Table in SQLite
SQLite is an embedded database that doesn't use a database like Oracle in the background to operate. The SQLite offers some features which are that it is a serverless architecture, quick, self-contained, reliable, full-featured SQL database engine. SQLite does not require any server to perform queries and operations on the database. In this article
3 min read
How to Select Rows from a Table that are Not in Another Table?
In MySQL, the ability to select rows from one table that do not exist in another is crucial for comparing and managing data across multiple tables. This article explores the methods to perform such a selection, providing insights into the main concepts, syntax, and practical examples. Understanding how to identify and retrieve rows that are absent
3 min read
MySQL Drop Database
In Database Management Systems managing databases involves not only creating and modifying the data but also removing the databases when they are no longer needed and freeing the space occupied by them. MySQL offers a feature called DROP DATABASE, allowing users to delete databases. In this article, We will see How to Drop Databases in MySQL, vario
3 min read
How to Make a search function using Node Express and MYSQL
In this article, we will learn how to create a search function using Node with Express framework to search terms inside MYSQL tables. Prerequisites:MySQLNode JSExpress JSWe will discuss the following methods to search: Table of Content Searching term with partial matchSearching term with exact matchingSearching term in multiple columnsApproach to m
5 min read
MySQL Unique Index
In MySQL, a unique index is a crucial tool for ensuring that values in a specific column or a group of columns within a table are unique. This feature is essential to maintain data integrity by preventing duplicate entries where uniqueness is required. In this guide, we'll explore MySQL's unique index, covering its syntax, usage, benefits, and impo
6 min read
MySQL UPDATE JOIN
A widely used open-source relational database management system that allows you to efficiently store, organize, and retrieve data. Developed by Oracle, My SQL is widely used for building and managing databases that handle interactive websites and applications. We'll discuss the syntax, and demonstrate how this dynamic duo can efficiently modify dat
6 min read
MYSQL View
MySQL is an open-source RDBMS, i.e. Relational Database Management System which is maintained by Oracle. MySQL has support for major operating systems like Windows, MacOS, Linux, etc. MySQL makes it easy for users to interact with your relational databases, which store data in the form of tables. You can write SQL queries to get the required data f
11 min read
MySQL Insert Date Time
In today's world, working with data is now a data-to-data activity, so therefore managing data with proper data and time is also crucial. MySQL provides functionalities to handle data and time properly in the database. Understanding how to insert data and time into MySQL database with functions provided by MySQL. Let's understand with the help of e
4 min read
How to Combine MySQL IN and LIKE Operators?
In database management, MySQL stands as one of the most popular relational database management systems. As developers strive to extract specific data from their databases, the judicious use of SQL operators becomes imperative. Among these operators, the IN and LIKE operators play crucial roles in facilitating flexible and precise data retrieval. Th
4 min read
Nested Select Statement in MySQL
The relational databases, the ability to retrieve and manipulate data with precision is a cornerstone of effective database management. MySQL, a popular relational database management system, provides a powerful tool called the Nested SELECT statement that empowers developers to perform complex and versatile data queries. So, In this article we wil
5 min read
How to Check MySQL Database
SQL stands for Structured Query Language which is a computer language for storing, manipulating, and retrieving data stored in relational database management systems (RDBMS). SQL was developed at IBM by Donald Chamberlin, Donald C. Messerli, and Raymond F. Boyce in the year 1970s. MySQL is an open-source Relational Database Management System that s
4 min read
three90RightbarBannerImg