Check DDL for objects present in MYSQL database

Generate DDL for table / view / function/ Procedure / Trigger / indexes in MySQL

Generate DDL for Table in MySQL

show create table table_name;
Example:
show create table hr.employees; 

Generate DDL for View in MySQL

SHOW CREATE VIEW view_name
Example
Show create view employee_view;

OR 
SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_SCHEMA = 'hr' AND TABLE_NAME = 'employees';

Generate DDL for Function in MySQL

SHOW CREATE FUNCTION func_name

Generate DDL for Procedure in MySQL

SHOW CREATE PROCEDURE proc_name

Generate DDL for triggers in MySQL

SHOW TRIGGERS [{FROM | IN} db_name]
 [LIKE 'pattern' | WHERE expr]
Example:
SHOW TRIGGERS LIKE 'EMP%'

OR
SELECT * FROM INFORMATION_SCHEMA.TRIGGERS
WHERE TRIGGER_SCHEMA='HR' AND TRIGGER_NAME='emp_trigger'\G

Generate DDL for indexes in MySQL

SHOW {INDEX | INDEXES | KEYS}
    {FROM | IN} tbl_name
    [{FROM | IN} db_name]
    [WHERE expr]

Example 
SHOW INDEX FROM employees;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.