在SQL Server的企业版中,可以通过使用脚本表为创建为来为现有表生成create语句。这将为包含索引的表生成完整的create语句。是否可以在T-SQL中执行任何操作,从而将表定义复制到新表中?
In the Enterprise version of SQL Server it is possible to generate the create statement for a pre-existing table by using 'Script Table as', "Create to". This generates the full create statement for the table including indices. Is there any way to do this in T-SQL and therefore be able to copy a table definition to a new table?
推荐答案可以直接复制SSMS功能的直接T-SQL中没有开箱即用的东西。
Nothing simply available out of the box in straight T-SQL which exactly replicates what SSMS does.
但是,您可以通过元数据( INFORMATION_SCHEMA.COLUMNS 等),我已经相当成功地做到了。请注意,索引不在 INFORMATION_SCHEMA 中,而是在sys.indexes中。
However, you can get to this through the metadata (INFORMATION_SCHEMA.COLUMNS etc), and I have done this fairly successfully. Note that the indexes are not in INFORMATION_SCHEMA - they are in sys.indexes.
看看本文,其中可能包含您想要的大部分内容。
Have a look at this article which probably has most of what you want.
更多推荐
SQL Server复制全表定义
发布评论