Skip to content
Related Articles

Related Articles

Improve Article

How to Show Schema of a Table in MySQL Database?

  • Difficulty Level : Hard
  • Last Updated : 26 Sep, 2021

The term “schema” refers to the organization of data as a blueprint of how the database is constructed (divided into database tables in the case of relational databases). The formal definition of a database schema is a set of formulas (sentences) called integrity constraints imposed on a database. In this article, we will learn how to display the Schema of a Table with the help of some SQL queries.

Step 1: Creating the Database

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

For the purpose of demonstration, we will be creating a Participant table in a database called “GeeksForGeeksDatabase“.

Query:



CREATE DATABASE GeeksForGeeksDatabase;

 

Step 2: Using the Database

Use the below SQL statement to switch the database context to GeeksForGeeksDatabase.

Query:

USE GeeksForGeeksDatabase;

Step 3: Table Definition

Query:



CREATE TABLE Geeks(
GeekID INTEGER PRIMARY KEY,
GeekName VARCHAR(255) NOT NULL,
GeekRank INTEGER NOT NULL,
GeekSchool VARCHAR(255) NOT NULL
);

Step 4:To display the table structure (Schema) in SQL

In Oracle, we use this query:

Query:

DESC tableName

In the MySQL database, we use this query:

Query:

DESCRIBE databasename.tableName;

In SQL Server we use Transact-SQL :

Query:

EXEC sp_help 'dbo.tableName';

Using the above query we got the whole description of the table, its properties like column names, data types used for each column, constraints.

My Personal Notes arrow_drop_up
Recommended Articles
Page :