SQL Server复制全表定义 [英] SQL Server copy full table definition

查看:92
本文介绍了SQL Server复制全表定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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复制全表定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆