编写来自 SQL Server 数据库的所有数据的脚本

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

Script all data from SQL Server database

sqlsql-servertsqlsql-server-2008ssms

提问by Sergey Metlov

I have two databases with equivalent structure and I need to extract data from one of them in form of INSERTstatements (generate script to apply it on the other database).

我有两个结构相同的数据库,我需要以INSERT语句的形式从其中一个数据库中提取数据(生成脚本以将其应用于另一个数据库)。

How can I do it using Management Studio?

如何使用 Management Studio 执行此操作?

采纳答案by marc_s

You could use the freeSSMS Toolpackadd-in for SQL Server Management Studio.

您可以使用SQL Server Management Studio的免费SSMS 工具包加载项。

See the section on Generate Insert statements from resultsets, tables or database

请参阅有关从结果集、表或数据库生成插入语句的部分

Update:OK, for SSMS Toolpack in SSMS 2012, a licensing scheme has been introduced. SSMS Toolpack for earlier versions of SSMS are however still free.

更新:好的,对于 SSMS 2012 中的 SSMS 工具包,已经引入了许可方案。然而,SSMS 早期版本的 SSMS 工具包仍然是免费的。

回答by Mitch Wheat

SSMS supports scripting all data as INSERTS in 2k8:

SSMS 支持将所有数据脚本化为 2k8 中的 INSERTS:

Right click on a database and select Tasks->Generate Scripts...

右键单击数据库并选择任务-> 生成脚本...

Pick only the tables, Click Next.

仅选择表,单击下一步。

Click on the Advanced button. Scroll down and select "Types of data to script" == Data Only

单击高级按钮。向下滚动并选择“要编写脚本的数据类型”==仅数据

enter image description here

在此处输入图片说明

Decide whether you want results in a new query window or a file. Click on to Finish.

决定是在新查询窗口还是文件中获得结果。单击以完成。

You then change the using DBnameat the top of the script.

然后更改using DBname脚本顶部的 。

回答by ShakirAhmad

You can do it with SQL Server Management Studio. Here are the steps - as Mitch Wheat describes above (for SQL Server Management Studio 2012):

您可以使用 SQL Server Management Studio 来完成。以下是步骤 - 正如上面 Mitch Wheat 所描述的(对于 SQL Server Management Studio 2012):

  1. Right-click your database.
  2. Select Tasks > Generate Scripts...
  3. Introduction Step. Click Next.
  4. Choose Objects. Select entire database or selected objects. Click Next.
  5. Set Scripting Options. Here's the key step. In order to get all data and objects, click the Advanced button. Then in the Advanced Scripting Options, set the value for Types of data to scriptto Schema and data.
  6. Click OK. Then Next and Finish.
  1. 右键单击您的数据库。
  2. 选择任务 > 生成脚本...
  3. 介绍步骤。点击下一步。
  4. 选择对象。选择整个数据库或选定的对象。点击下一步。
  5. 设置脚本选项。这是关键步骤。要获取所有数据和对象,请单击“高级”按钮。然后在Advanced Scripting Options 中,将Types of data to script的值设置为Schema 和 data
  6. 单击确定。然后下一步和完成。

You will have a script file that contains both database schema and data.

您将拥有一个包含数据库架构和数据的脚本文件。