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
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.
Please Login to comment...