
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Generate table DDL via a query on MySQL and SQL Server?
The DDL stands for Data Definition Language. To generate the table DDL via query, you can use show create command.
The syntax is as follows
SHOW CREATE TABLE yourTableName;
The above syntax is MySQL specific. Suppose, we have a table with the name ‘DDLOfTableStudent’.
First, create a table with the name ‘DDLOfTableStudent’. The query to create a table is as follows
mysql> create table DDLOfTableStudent -> ( -> StudentId int, -> StudentFirstName varchar(100), -> StudentLastName varchar(100), -> StudentAddress varchar(200), -> StudentAge int, -> StudentMarks int -> ); Query OK, 0 rows affected (0.84 sec)
Use the above syntax to know the DDL of a table. The query is as follows
mysql> SHOW CREATE TABLE DDLOfTableStudent;
The following is the output displaying the DDL
+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | DDLOfTableStudent | CREATE TABLE `ddloftablestudent` (`StudentId` int(11) DEFAULT NULL,`StudentFirstName` varchar(100) DEFAULT NULL,`StudentLastName` varchar(100) DEFAULT NULL,`StudentAddress` varchar(200) DEFAULT NULL,`StudentAge` int(11) DEFAULT NULL,`StudentMarks` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci | +-------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
- Related Articles
- Difference between MySQL and SQL Server
- Show MySQL host via SQL Command?
- SQL Query to Convert Rows to Columns in SQL Server
- Database Wars: MSSQL Server, Oracle PL/SQL and MySQL
- MySQL LIMIT clause equivalent for SQL SERVER?
- How to write a MySQL “LIMIT” in SQL Server?
- \nLoad and unload a table in SAP HANA using SQL query
- Equivalent of SQL Server IDENTITY Column in MySQL?
- Create table SQL query in SAP HANA
- How to generate a “create table” command based on an existing table in MySQL?
- Mean and Mode in SQL Server
- Difference between Oracle and SQL Server
- The equivalent of SQL Server function SCOPE_IDENTITY() in MySQL?
- SQL Server Query to Find All Permissions/Access for All Users in a Database
- Implement Dynamic SQL query inside a MySQL stored procedure?

Advertisements