Generate table DDL via query on MySQL and SQL Server

Bob picture Bob · Oct 8, 2009 · Viewed 33.1k times · Source

Is there an easy way to extract table DDL information, via a query, using either Ms or My SQL server? (preferably both?)

For example, using MySQL Administrator / Navicat for MySql, there is a "DDL" function, which generates the "create table foo (....)" script.

Is there any way to get this information from a query itself, such as:

Select DDL from foo where table_name='bar';

Any have the "Create table bar (.....)" returned to me?

If not - any suggestions?

Answer

longneck picture longneck · Oct 8, 2009

it's mysql-specific, but SHOW CREATE TABLE <table-name> gives you the DDL for a table.