How to Show Schema of a Table in MySQL Database?
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“.
CREATE DATABASE GeeksForGeeksDatabase;
Step 2: Using the Database
Use the below SQL statement to switch the database context to GeeksForGeeksDatabase.
Step 3: Table Definition
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:
In the MySQL database, we use this query:
In SQL Server we use Transact-SQL :
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.