Generate table DDL via query on MySQL and SQL Server
Solution 1
it's mysql-specific, but SHOW CREATE TABLE <table-name>
gives you the DDL for a table.
Solution 2
You have to create that yourself.
You can query INFORMATION_SCHEMA.COLUMNS
for the column name and data type.
Solution 3
You can't get the CREATE Table
text in a cross platform way, but you can get enough information to build it yourself from the INFORMATION_SCHEMA
views.
Admin
Updated on August 15, 2020Comments
-
Admin over 3 years
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?
-
tftdias over 9 yearsUpvoted. Just to be more specific about the syntax, it would be
SHOW CREATE TABLE table_name
. source: dev.mysql.com/doc/refman/5.0/en/show-create-table.html