Generate table DDL via query on MySQL and SQL Server

北战南征 提交于 2019-12-12 07:39:31

问题


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?


回答1:


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




回答2:


You have to create that yourself.

You can query INFORMATION_SCHEMA.COLUMNS for the column name and data type.




回答3:


You can't get the the CREATE Table text in a cross platform way, but you can get enough information to build it yourself from the INFORMATION_SCHEMA views.



来源:https://stackoverflow.com/questions/1537951/generate-table-ddl-via-query-on-mysql-and-sql-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!