使用 Microsoft SQL Server 管理复制 TABLE

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3602346/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 07:21:55  来源:igfitidea点击:

Duplicating a TABLE using Microsoft SQL Server Management

sqlsql-servertsqlssms

提问by Alex

Need to duplicate a TABLE using Microsoft SQL Management Studio 2008

需要使用复制表 Microsoft SQL Management Studio 2008

The TABLE needs to duplicate all table row (Primary Key) ID as well.

TABLE 还需要复制所有表行(主键)ID。

回答by SQLMenace

In SSMS open a new query window and then do something like

在 SSMS 中打开一个新的查询窗口,然后执行类似的操作

SELECT * INTO NewTable
FROM OldTable

change NewTable to the name that the new table should have, change OldTable to the name of the current table

把NewTable改成新表应该有的名字,把OldTable改成当前表的名字

this will copy over the basic table structure and all the data...it will NOT do any of the constraints, you need to script those out and change the names in those scripts

这将复制基本表结构和所有数据......它不会执行任何约束,您需要将它们编写出来并更改这些脚本中的名称

回答by D?nu

I prefere the copy / paste solution as it is documented here. It works for Management Studio 2005 upwards. You just have to select all columns in the design then Edit -> Copy. Create a new table and the Edit -> Paste. This, at least, copies default values but of course doesn't copy the actual data.

我更喜欢复制/粘贴解决方案,因为它记录在此处。它适用于 Management Studio 2005 以上。您只需选择设计中的所有列,然后编辑 -> 复制。创建一个新表和编辑 -> 粘贴。这至少会复制默认值,但当然不会复制实际数据。

回答by dshefman

To duplicate a table and the data rows in the table, right-click on the database that contains the table you want to duplicate, then click 'Tasks' then 'Import Data...". See the screenshot below for visual representation. Then, follow the instructions in the "SQL Server Import and Export Wizard." Select the table to be duplicated as the 'source' and write in a made-up table name of your choice for the 'destination'. When finished on the last screen (see screenshot below), click 'Next', then 'Finish' and the Wizard will show you the progress of the data transfer until complete.

要复制表和表中的数据行,请右键单击包含要复制的表的数据库,然后单击“任务”,然后单击“导入数据...”。请参阅下面的屏幕截图以获得直观表示。然后, 按照“SQL Server 导入和导出向导”中的说明进行操作。选择要复制的表作为“源”,并为“目标”输入您选择的虚构表名。在最后一个屏幕上完成后(请参见下面的屏幕截图),单击“下一步”,然后单击“完成”,向导将向您显示数据传输的进度,直至完成。

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by Dane Stevens

An easy way to copy a table and all of it's data:

复制表及其所有数据的简单方法:

SELECT * INTO 
    [DATABASE_NAME].[SCHEMA_NAME].[NEW_TABLE_NAME] 
FROM 
    [DATABASE_NAME].[SCHEMA_NAME].[OLD_TABLE_NAME]

The SCHEMA_NAME is often dbo

SCHEMA_NAME 通常是 dbo