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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Nothing simply available out of the box in straight T-SQL which exactly replicates what SSMS does.
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.
回答2:
Create the script to a new query window, then modify the database name and run it