SQL DESCRIBE TABLE: Get a Description of a Table with Example | EDUCBA (2024)

Updated August 30, 2023

SQL DESCRIBE TABLE: Get a Description of a Table with Example | EDUCBA (1)

Introduction to SQL DESCRIBE TABLE

SQL DESCRIBE TABLE is a SQL statement that is accountable for telling something about a specific table in the database. If we want to show the structure of a database table or tables in the server then, we will use the SQL command DESCRIBE or other keyword DESC, which is identical to DESCRIBE one. To get information about the table present in the database and find the attributes related to it, we will use either DESCRIBE or DESC, where both are Case Insensitive and produce a similar output. We implement the DESCRIBE TABLE statement for getting the info about the name of the column, data type of the column, NULL or NOT NULL attributes of column, and table with database size accuracy along with If NUMERIC type scale.

ADVERTIsem*nT Popular Course in this categorySQL Course Bundle - 51 Courses in 1 | 6 Mock Tests

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax of SQL DESCRIBE TABLE

Let us elaborate the elementary syntax to show the structure of DESCRIBE TABLE command in SQL server:

DESCRIBE | DESC [TableName | ViewName];

The terms mentioned above are described below:

  • The TableName denotes the name of the table in the database for which we want to see the structure.
  • ViewName also denotes the name of the view created for the table and we wish to describe the view structure.

We can also monitor another syntax type in advance level as follows:

[DESCRIBE | DESC] TABLE{name}[ TYPE = (STAGE | COLUMNS) ];
  • Here, the {name} defines an identifier for the particular table mentioned to describe it. We can enclose the whole string using double quotes which are case-sensitive when the identifier includes spaces or special characters.
  • The TYPE = (STAGE | COLUMNS) term defines whether to show the table columns or the stage properties which comprises of their default and current values for the table.
  • But by default the server uses TYPE = COLUMNS, if the TYPE keyword not provided in the query.
  • Also, it should be remembered that the query with criteria TYPE = STAGE cannot be applied for views as views do not contain stage properties.

How to DESCRIBE TABLE in SQL?

  • DESCRIBE can be said as a synonym for the command EXPLAIN TABLE. These both statements when executed will provide information about all table columns.
  • Therefore, using DESCRIBE TABLE in SQL it will tell you either about the columns present in that specific table or its current values type and also the default values for a table’s stage properties.
  • When we execute DESCRIBE TABLE command in our database we will be able to view the structure of the table in a describe tab but not on the console tab of the system software.
  • The SQL DESCRIBE TABLE query will make us to know about the organization of table that consists of name of table column with data type values such as VARCHAR, CHAR, INT, FLOAT, TIME, DATE, NUMBER or any XML type, used for the respective fields in the table, also it displays column having NULL or NOT NULL database objects that says if the column do include null values or not.
  • Thus, the SQL DESCRIBE TABLE is beneficial for fetching out details about the current table present in the database.

Examples of SQL DESCRIBE TABLE

Given below are the examples of SQL DESCRIBE TABLE:

Example #1

Simple Example using DESCRIBE TABLE command.

Suppose, we have taken a table as demo to use the DESCRIBE. TABLE command on it and view the result. We have a table named Books in our database with fields as BookID, BookName, Language, Price and each having different data type defined at the time of table creation.

The contents of the table can be shown as below:

Code:

SELECT * FROM Books;

Output:

SQL DESCRIBE TABLE: Get a Description of a Table with Example | EDUCBA (2)

Now, let us apply simply the DESCRIBE TABLE query written as below:

Code:

DESCRIBE Books;

Output:

SQL DESCRIBE TABLE: Get a Description of a Table with Example | EDUCBA (3)

As you can see in the output above that the column names of the table Books with Type, NULL attribute, Key, Default values and even Extra attribute are described by the DESCRIBE TABLE statement.

The data type values with its length and NULL attribute with YES/NO values for its presence and PRIMARY key are also provided in the structure of the table. Note that the YES in NULL column says that the value for that specific column of table can be NULL and NO denotes we cannot place or insert NULL values.

Example #2

Example using DESC TABLE command.

Assume that we are having a table named Emp_Data present in our database created as follows:

Code:

CREATE TABLE Emp_Data(Emp_ID INT AUTO_INCREMENT PRIMARY KEY, Emp_Name VARCHAR(255), Emp_Salary INT NOT NULL DEFAULT 0);

After completing the structure of table let us fill in some records as below:

Code:

INSERT INTO `emp_data`(`Emp_ID`, `Emp_Name`, `Emp_Salary`) VALUES(10,'Rita',5000),(11, 'Sahil',7500)(13, 'Nikhil',7300);

Now, displaying the contents of table Emp_Data:

Code:

SELECT * FROM Emp_Data;

Output:

SQL DESCRIBE TABLE: Get a Description of a Table with Example | EDUCBA (4)

Next, we will query using DESC TABLE command to get the details of the table by the statement below:

Code:

DESC Emp_Data;OR,DESCRIBE Emp_Data;

Output:

SQL DESCRIBE TABLE: Get a Description of a Table with Example | EDUCBA (5)

As you can view while creating we have added default value for the Emp_Salary column and therefore when described the result shows DEFAULT as 0 in Emp_Salary row. Similarly, for in Emp_ID row you can see the auto_increment value in the Extra column which is the attribute added in table making time as mentioned in the above query.

Example #3

Example with DESCRIBE TABLE command Vs EXPLAIN TABLE command.

Let us take the table Customer with fields: CustomerID, CustomerName, Credit_Limit and City having their respective data types and other attributes.

View the table:

Code:

SELECT * FROM Customer;

Output:

SQL DESCRIBE TABLE: Get a Description of a Table with Example | EDUCBA (6)

The EXPLAIN Table and DESCRIBE Table commands are similar in working and generates the same result rows. We can say that both are synonyms to each other and any of them in SQL server can be applied to retrieve information about a particular table.

See the queries below with output simultaneously:

Code:

DESCRIBE Customer;

Output:

SQL DESCRIBE TABLE: Get a Description of a Table with Example | EDUCBA (7)

Code:

EXPLAIN Customer;

Output:

SQL DESCRIBE TABLE: Get a Description of a Table with Example | EDUCBA (8)

As you can see both outputs are identical with DESCRIBE and EXPLAIN Table commands as well.

Conclusion

The DESCRIBE query in SQL is implemented to display the definitions of a list of columns for a specified database table. SQL DESCRIBE Table command should be executed on only our system software not it any editor because it won’t run there. We need to run this DESCRIBE query on the database installed on our own system server.

Recommended Articles

We hope that this EDUCBA information on “SQL DESCRIBE TABLE” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. SQL DML Commands
  2. What is SQL
  3. SQL with Clause
  4. SQL TRUNCATE()

ADVERTIsem*nT

MICROSOFT POWER BI Course Bundle - 8 Courses in 1 34+ Hours of HD Videos 8 Courses Verifiable Certificate of Completion Lifetime Access4.5

ADVERTIsem*nT

ADVERTIsem*nT

MICROSOFT AZURE Course Bundle - 15 Courses in 1 | 12 Mock Tests 73 of HD Videos 15 Courses Verifiable Certificate of Completion Lifetime Access4.5

ADVERTIsem*nT

KALI LINUX Course Bundle - 6 Courses in 1 20+ Hours of HD Videos 6 Courses Verifiable Certificate of Completion Lifetime Access4.5
Primary Sidebar

");jQuery('.cal-tbl table').unwrap("

");jQuery("#mobilenav").parent("p").css("margin","0");jQuery("#mobilenav .fa-bars").click(function() {jQuery('.navbar-tog-open-close').toggleClass("leftshift",7000);jQuery("#fix-bar").addClass("showfix-bar");/*jQuery(".content-sidebar-wrap").toggleClass("content-sidebar-wrap-bg");jQuery(".inline-pp-banner").toggleClass("inline-pp-banner-bg");jQuery(".entry-content img").toggleClass("img-op");*/jQuery("#fix-bar").toggle();jQuery(this).toggleClass('fa fa-close fa fa-bars');});jQuery("#mobilenav .fa-close").click(function() {jQuery('.navbar-tog-open-close').toggleClass("leftshift",7000);jQuery("#fix-bar").removeClass("showfix-bar");jQuery("#fix-bar").toggle();jQuery(this).toggleClass('fa fa-bars fa fa-close');/*jQuery(".content-sidebar-wrap").toggleClass("content-sidebar-wrap-bg");jQuery(".inline-pp-banner").toggleClass("inline-pp-banner-bg");jQuery(".entry-content img").toggleClass("img-op");*/});});

SQL DESCRIBE TABLE: Get a Description of a Table with Example | EDUCBA (2024)
Top Articles
Latest Posts
Article information

Author: Otha Schamberger

Last Updated:

Views: 6124

Rating: 4.4 / 5 (55 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Otha Schamberger

Birthday: 1999-08-15

Address: Suite 490 606 Hammes Ferry, Carterhaven, IL 62290

Phone: +8557035444877

Job: Forward IT Agent

Hobby: Fishing, Flying, Jewelry making, Digital arts, Sand art, Parkour, tabletop games

Introduction: My name is Otha Schamberger, I am a vast, good, healthy, cheerful, energetic, gorgeous, magnificent person who loves writing and wants to share my knowledge and understanding with you.