在 SQL Server Management Studio 中生成脚本

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

Generate script in SQL Server Management Studio

sqldatabasesql-server-2008database-scripts

提问by General_9

If I have a table with data in a database in SQL Server, how can I generate a script that will create the table and add the data too?

如果我在 SQL Server 的数据库中有一个包含数据的表,我如何生成一个脚本来创建表并添加数据?

If I right click on the table then select Script Table As > Create to > File, that generates a script to just create the table without the data. What I need is a script that creates the table and adds the data that is already existing in the table or 2 separate scripts, one that creates the table and one that adds the data.

如果我右键单击表然后选择Script Table As > Create to > File,则会生成一个脚本来创建没有数据的表。我需要的是一个脚本来创建表并添加表中已经存在的数据或 2 个单独的脚本,一个创建表,一个添加数据。

回答by Ali Issa

Here what you have to do:

在这里你必须做的:

  1. right click the database (not the table) and select tasks --> generate scripts
  2. Next --> select the requested table/tables (from select specific database objects)
  3. next --> click advanced --> types of data to script = schema and data
  4. next and finish
  1. 右键单击数据库(不是表)并选择任务 --> 生成脚本
  2. 下一步 --> 选择请求的表(从选择特定的数据库对象中)
  3. 下一步 --> 点击高级 --> 数据类型到脚本 = 模式和数据
  4. 下一步并完成

回答by Oleg Dok

Use SSMS scripting feature (Rightclick on database->Tasks->Generate Scripts)

使用 SSMS 脚本功能(右键单击数据库-> 任务-> 生成脚本)

or

或者

use SSMS Tools Pack

使用SSMS 工具包

回答by KKZone

Here You can see step by step process of Generate script in SQL Server Management Studio :

在这里您可以看到在 SQL Server Management Studio 中生成脚本的分步过程:

Step 1: Right Click on Your Database --> Select Task-->Generate Script..

第 1 步:右键单击您的数据库--> 选择任务--> 生成脚本..

Step 2: Select Next in Script Wizard

步骤 2:在脚本向导中选择下一步

Step 3: Select Script Entire Database

步骤 3:选择脚本整个数据库

Step 4:Choose Your File Name

第 4 步:选择您的文件名

and Finish

并完成

Now you can use your script file.

现在您可以使用您的脚本文件。