Lompat ke konten Lompat ke sidebar Lompat ke footer

how to see what is in a table in sql

SQL DESCRIBE TABLE

Introduction to SQL DESCRIBE TABLE

SQL DESCRIBE TABLE is a SQL statement that is answerable for telling something about a specific table in the database. If nosotros want to show the structure of a database table or tables in the server then, we volition utilise the SQL control Depict or other keyword DESC, which is identical to Depict one. To go data virtually the table nowadays in the database and find the attributes related to it, nosotros will utilize either DESCRIBE or DESC, where both are Case Insensitive and produce a like output. Nosotros implement the Describe Tabular array statement for getting the info about the name of the column, information type of the cavalcade, NULL or NOT Aught attributes of cavalcade, and tabular array with database size accurateness along with If NUMERIC blazon scale.

Syntax of SQL Draw TABLE

Let us elaborate the elementary syntax to prove the construction of Depict Table command in SQL server:

Draw | DESC [TableName | ViewName];

The terms mentioned above are described below:

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

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

[Describe | DESC] TABLE{name}[ TYPE = (Stage | COLUMNS) ];

  • Here, the {proper noun} defines an identifier for the particular table mentioned to describe it. We can enclose the whole string using double quotes which are example-sensitive when the identifier includes spaces or special characters.
  • The Blazon = (STAGE | COLUMNS) term defines whether to evidence the tabular array columns or the stage backdrop which comprises of their default and current values for the table.
  • Merely by default the server uses Type = COLUMNS, if the TYPE keyword not provided in the query.
  • Too, information technology should be remembered that the query with criteria Blazon = Stage cannot be applied for views every bit views do not contain stage backdrop.

How to Describe TABLE in SQL?

  • DESCRIBE can be said as a synonym for the command Explain TABLE. These both statements when executed volition provide information nigh all tabular array columns.
  • Therefore, using DESCRIBE TABLE in SQL it volition tell y'all either about the columns present in that specific tabular array or its current values type and also the default values for a tabular array'south stage properties.
  • When we execute DESCRIBE Tabular array 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 organization software.
  • The SQL DESCRIBE TABLE query will brand us to know virtually the organization of table that consists of name of tabular array column with data type values such as VARCHAR, CHAR, INT, FLOAT, Time, DATE, NUMBER or any XML type, used for the corresponding fields in the table, as well it displays column having NULL or Non NULL database objects that says if the cavalcade do include zip 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 Tabular array

Given beneath are the examples of SQL Describe TABLE:

Example #1

Simple Instance using Draw Table command.

Suppose, we have taken a table as demo to utilise the Draw. 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 dissimilar data type defined at the time of table creation.

The contents of the table can be shown as below:

Lawmaking:

SELECT * FROM Books;

Output:

SQL DESCRIBE TABLE 1

Now, allow us apply simply the Describe Table query written equally beneath:

Code:

Depict Books;

Output:

Books

Equally you can see in the output above that the column names of the table Books with Blazon, Naught attribute, Key, Default values and even Extra aspect are described by the DESCRIBE TABLE argument.

The information type values with its length and NULL attribute with Yep/NO values for its presence and PRIMARY key are as well provided in the structure of the tabular array. Notation that the YES in NULL cavalcade says that the value for that specific column of table can be Goose egg and NO denotes nosotros cannot place or insert NULL values.

Example #2

Example using DESC Tabular array control.

Presume 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 Main Fundamental, Emp_Name VARCHAR(255), Emp_Salary INT Not NULL DEFAULT 0);

After completing the structure of table permit u.s.a. fill up in some records every bit beneath:

Code:

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

Now, displaying the contents of tabular array Emp_Data:

Lawmaking:

SELECT * FROM Emp_Data;

Output:

SQL DESCRIBE TABLE 3

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

Code:

DESC Emp_Data;
OR,
Draw Emp_Data;

Output:

DESC

As you can view while creating we take added default value for the Emp_Salary column and therefore when described the result shows DEFAULT equally 0 in Emp_Salary row. Similarly, for in Emp_ID row yous can run across the auto_increment value in the Extra column which is the attribute added in table making time as mentioned in the to a higher place query.

Instance #iii

Example with DESCRIBE Tabular array 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:

Vs EXPLAIN

The Explain Tabular array and DESCRIBE Table commands are like in working and generates the same upshot rows. We tin can say that both are synonyms to each other and whatsoever of them in SQL server tin can be applied to call up data nigh a particular tabular array.

Come across the queries beneath with output simultaneously:

Code:

DESCRIBE Customer;

Output:

SQL DESCRIBE TABLE 6

Code:

Explicate Client;

Output:

SQL DESCRIBE TABLE 7

Every bit yous can encounter both outputs are identical with DESCRIBE and Explicate Table commands likewise.

Conclusion

The DESCRIBE query in SQL is implemented to display the definitions of a listing of columns for a specified database tabular array. SQL Draw Table command should be executed on merely our organisation software not it whatsoever editor because information technology won't run in that location. We need to run this DESCRIBE query on the database installed on our own system server.

Recommended Articles

This is a guide to SQL DESCRIBE Table. Hither we discuss the introduction, how to Draw Table in SQL? and examples respectively. You may too have a await at the post-obit articles to learn more than –

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

wilsonmandetlable1940.blogspot.com

Source: https://www.educba.com/sql-describe-table/

Posting Komentar untuk "how to see what is in a table in sql"