通过在 MySQL 和 SQL Server 上查询生成表 DDL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1537951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generate table DDL via query on MySQL and SQL Server
提问by longneck
Is there an easy way to extract table DDL information, via a query, using either Ms or My SQL server? (preferably both?)
是否有使用 Ms 或 My SQL 服务器通过查询提取表 DDL 信息的简单方法?(最好是两个?)
For example, using MySQL Administrator / Navicat for MySql, there is a "DDL" function, which generates the "create table foo (....)" script.
例如,使用 MySQL Administrator/Navicat for MySql,有一个“DDL”函数,它生成“create table foo(....)”脚本。
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?
如果没有 - 有什么建议吗?
回答by longneck
it's mysql-specific, but SHOW CREATE TABLE
gives you the DDL for a table.
它是特定于 mysql 的,但SHOW CREATE TABLE
为您提供了表的 DDL。
回答by Squirrel
You have to create that yourself.
你必须自己创造。
You can query INFORMATION_SCHEMA.COLUMNS
for the column name and data type.
您可以查询INFORMATION_SCHEMA.COLUMNS
列名和数据类型。
回答by Joel Coehoorn
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.
您无法CREATE Table
以跨平台的方式获取文本,但是您可以获得足够的信息来从INFORMATION_SCHEMA
视图中自己构建它。