如何将 Sql Server 备份到 sql 文件?

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

How to backup Sql Server to sql file?

sqlsql-serverdatabasebackup

提问by IAdapter

In "Back UP" I only get a bak file, but I would like to create .sql file

在“备份”中,我只得到一个 bak 文件,但我想创建 .sql 文件

回答by p.campbell

Use SQL Server's Generate Scripts commend

使用 SQL Server 的生成脚本推荐

  • right click on the database; Tasks -> Generate Scripts
  • select your tables, click Next
  • click the Advanced button
  • find Types of data to script - choose Schema and Data.
  • you can then choose to save to file, or put in new query window.
  • results in CREATEand INSERTstatements for all table data selected in bullet 2.
  • 右键单击数据库;任务 -> 生成脚本
  • 选择你的表,点击下一步
  • 单击高级按钮
  • 找到要编写脚本的数据类型 - 选择Schema 和 Data
  • 然后您可以选择保存到文件,或放入新的查询窗口。
  • 结果CREATEINSERT语句用于在项目符号 2 中选择的所有表数据。

SQL Server Generate Scripts Data

SQL Server 生成脚本数据

回答by Simon

This is a possible duplicate of: SQL script to get table content as "SELECT * FROM tblname"

这可能是以下内容的重复:SQL 脚本以获取表内容为“SELECT * FROM tblname”

To do a full database backup to File/Query you can use the 'Generate Scripts...' option on the Database.

要对文件/查询进行完整的数据库备份,您可以使用数据库上的“生成脚本...”选项。

Open SQL Server Management studio, right click on the database and choose 'Tasks->Generate Scripts...'

打开 SQL Server Management Studio,右键单击数据库并选择“任务->生成脚本...”

Then use the wizard to backup the database. You can script the whole database or parts of it. Two important options: In the 'Advanced' section, you will probably want to ensure 'Type of backup = 'Schema and Data' and the 'Script Statistics' is on.

然后使用向导备份数据库。您可以编写整个数据库或部分数据库的脚本。两个重要的选项:在“高级”部分,您可能需要确保“备份类型 = '架构和数据'”和“脚本统计信息”已打开。

This will produce a *.sql file that you can use as a backup that includes the schema and table data.

这将生成一个 *.sql 文件,您可以将其用作包含架构和表数据的备份。

回答by Travis Heeter

Ok, I read through most of these, but I had no "advanced button". But, there is still a way to do it, it's just a little hard to find, so here you go:

好的,我通读了其中的大部分内容,但是我没有“高级按钮”。但是,仍然有一种方法可以做到,只是有点难找到,所以你去吧:

enter image description here

在此处输入图片说明

回答by cusimar9

You can generate a script from a database, see http://msdn.microsoft.com/en-us/library/ms178078.aspx

您可以从数据库生成脚本,请参阅http://msdn.microsoft.com/en-us/library/ms178078.aspx

回答by squillman

If you want to create a script of your database you right-click on the databases and Generate Scripts (it's in different sub-menus depending on what version of SQL and Enterprise Manager / SQL Server Management studio you're using).

如果要创建数据库脚本,请右键单击数据库并生成脚本(它位于不同的子菜单中,具体取决于您使用的 SQL 和企业管理器/SQL Server Management Studio 的版本)。

That will, however, only get you the database objects. It will not generate scripts for data. Backing up a database will give you all of the database objects as well as the data, depending on what recovery model your database is set to.

但是,这只会让您获得数据库对象。它不会为数据生成脚本。备份数据库将为您提供所有数据库对象和数据,具体取决于您的数据库设置的恢复模型。

回答by DOK

This fellowmay have achieved what you are trying to do by creating the backup, and then restoring it and giving it a new name.

这个家伙可能已经通过创建备份,然后恢复它并给它一个新名称来实现你想要做的事情

This approach copies the data along with all of the database objects.

这种方法将数据与所有数据库对象一起复制。

回答by Pleun

If you want a file with insert statements for your data have a look here:

如果您想要一个包含数据插入语句的文件,请查看此处:

This procedure generates INSERT statements using existing data from the given tables and views. Later, you can use these INSERT statements to generate the data. It's very useful when you have to ship or package a database application. This procedure also comes in handy when you have to send sample data to your vendor or technical support provider for troubleshooting purposes.

此过程使用来自给定表和视图的现有数据生成 INSERT 语句。稍后,您可以使用这些 INSERT 语句来生成数据。当您必须运送或打包数据库应用程序时,它非常有用。当您必须将样本数据发送给供应商或技术支持提供商以进行故障排除时,此过程也会派上用场。

http://vyaskn.tripod.com/code.htm#inserts

http://vyaskn.tripod.com/code.htm#inserts