创建数据库快照 (Transact-SQL)Create a Database Snapshot (Transact-SQL)

08/10/2016

本文内容

适用于:Applies to: SQL ServerSQL Server(所有支持的版本)SQL ServerSQL Server (all supported versions)适用于:Applies to: SQL ServerSQL Server(所有支持的版本)SQL ServerSQL Server (all supported versions)

创建 SQL ServerSQL Server 数据库快照的唯一方式是使用 Transact-SQLTransact-SQL。The only way to create a SQL ServerSQL Server database snapshot is to use Transact-SQLTransact-SQL. SQL Server Management StudioSQL Server Management Studio 不支持创建数据库快照。does not support the creation of database snapshots.

开始之前Before You Begin

先决条件Prerequisites

可以使用任何恢复模式的源数据库必须满足以下先决条件:The source database, which can use any recovery model, must meet the following prerequisites:

服务器实例必须运行支持数据库快照的 SQL ServerSQL Server 版本。The server instance must be running an edition of SQL ServerSQL Server that supports database snapshot. 有关 SQL Server 2019 (15.x)SQL Server 2019 (15.x)中数据库快照支持的详细信息,请参阅 SQL Server 2016 各个版本支持的功能。For information about support for database snapshots in SQL Server 2019 (15.x)SQL Server 2019 (15.x), see Features Supported by the Editions of SQL Server 2016.

源数据库必须处于联机状态,除非该数据库是数据库镜像会话中的镜像数据库。The source database must be online, unless the database is a mirror database within a database mirroring session.

若要在镜像数据库中创建数据库快照,数据库必须处于同步 镜像状态。To create a database snapshot on a mirror database, the database must be in the synchronized mirroring state.

不能将源数据库配置为可缩放共享数据库。The source database cannot be configured as a scalable shared database.

源数据库不得包含 MEMORY_OPTIMIZED_DATA 文件组。The source database must not contain a MEMORY_OPTIMIZED_DATA filegroup.

重要

For information about other significant considerations, see Database Snapshots (SQL Server).

建议Recommendations

本节讨论以下最佳做法:This section discusses the following best practices:

最佳做法:命名数据库快照Best Practice: Naming Database Snapshots

创建数据库快照之前,考虑如何命名它们是非常重要的。Before creating snapshots, it is important to consider how to name them. 每个数据库快照都需要一个唯一的数据库名称。Each database snapshot requires a unique database name. 为了便于管理,数据库快照的名称可以包含标识数据库的信息,例如:For administrative ease, the name of a snapshot can incorporate information that identifies the database, such as:

源数据库的名称。The name of the source database.

表明新名称用于快照的指示信息。An indication that the new name is for a snapshot.

快照的创建日期和时间、序列号或一些其他的信息(例如一天中的某个时间)以区分给定的数据库上的连续快照。The creation date and time of the snapshot, a sequence number, or some other information, such as time of day, to distinguish sequential snapshots on a given database.

例如,假设有一系列的 AdventureWorks2012AdventureWorks2012 数据库快照。For example, consider a series of snapshots for the AdventureWorks2012AdventureWorks2012 database. 在上午 6 时和下午 6 时(基于 24 小时制)之间,Three daily snapshots are created at 6-hour intervals between 6 A.M. 以 6 个小时为间隔创建三个每日快照。and 6 P.M., based on a 24-hour clock. 每个每日快照保持 24 小时才被删除并被同一名称的新快照替换。Each daily snapshot is kept for 24 hours before being dropped and replaced by a new snapshot of the same name. 请注意,每个快照名称指明了小时,而非天:Note that each snapshot name indicates the hour, but not the day:

AdventureWorks_snapshot_0600

AdventureWorks_snapshot_1200

AdventureWorks_snapshot_1800

另外,如果这些每日快照创建的时间每天都变化,则推荐使用不太精确的命名约定,例如:Alternatively, if the creation time of these daily snapshots varies from day to day, a less precise naming convention might be preferable, for example:

AdventureWorks_snapshot_morning

AdventureWorks_snapshot_noon

AdventureWorks_snapshot_evening

最佳做法:限制数据库快照的数量Best Practice: Limiting the Number of Database Snapshots

随着时间的变化创建一系列快照可捕获源数据库的连续快照。Creating a series of snapshots over time captures sequential snapshots of the source database. 每个数据库快照会一直保存在系统中,直到被显式删除。Each snapshot persists until it is explicitly dropped. 因为每个快照会随着原始页的更新而不断增长,所以您可能想在创建新快照后通过删除旧的快照来节省空间。Because each snapshot will continue to grow as original pages are updated, you may want to conserve disk space by deleting an older snapshot after creating a new snapshot.

注意!Note! 若要还原到某个数据库快照,则需要从该数据库中删除所有其他快照。To revert to a database snapshot, you need to delete any other snapshots from that database.

最佳做法:将客户端连接到数据库快照Best Practice: Client Connections to a Database Snapshot

若要使用数据库快照,客户端需要知道它的位置。To use a database snapshot, clients need to know where to find it. 正在创建或删除另一个数据库快照时,用户可以从一个数据库快照读取。Users can read from one database snapshot while another is being created or deleted. 但是,如果用新快照替代现有快照,您需要将客户端重新定向到新快照。However, when you substitute a new snapshot for an existing one, you need to redirect clients to the new snapshot. 用户可以通过 SQL Server Management StudioSQL Server Management Studio手动连接到数据库快照。Users can manually connect to a database snapshot by means of SQL Server Management StudioSQL Server Management Studio. 但是,若要支持生产环境,您应该创建一个编程解决方案,该方案透明地将报表编写客户端定向到数据库的最新数据库快照。However, to support a production environment, you should create a programmatic solution that transparently directs report-writing clients to the latest database snapshot of the database.

权限Permissions

可创建数据库的任何用户都可以创建数据库快照;但是,若要创建镜像数据库的快照,你必须是 sysadmin 固定服务器角色的成员。Any user who can create a database can create a database snapshot; however, to create a snapshot of a mirror database, you must be a member of the sysadmin fixed server role.

如何创建数据库快照(使用 Transact-SQL)How to Create a Database Snapshot (Using Transact-SQL)

创建数据库快照To create a database snapshot

有关此过程的示例,请参阅本节后面的 示例 (Transact-SQL)。For an example of this procedure, see Examples (Transact-SQL), later in this section.

根据源数据库的当前大小,确保有足够的磁盘空间存放数据库快照。Based on the current size of the source database, ensure that you have sufficient disk space to hold the database snapshot. 数据库快照的最大大小为创建快照时源数据库的大小。The maximum size of a database snapshot is the size of the source database at snapshot creation.

使用 AS SNAPSHOT OF 子句对文件执行 CREATE DATABASE 语句。Issue a CREATE DATABASE statement on the files using the AS SNAPSHOT OF clause. 创建快照需要指定源数据库的每个数据库文件的逻辑名称。Creating a snapshot requires specifying the logical name of every database file of the source database. 语法如下所示:The syntax is as follows:

CREATE DATABASE database_snapshot_nameCREATE DATABASE database_snapshot_name

ONON

((

NAME =logical_file_name,NAME =logical_file_name,

FILENAME ='os_file_name'FILENAME ='os_file_name'

) [ ,...n ]) [ ,...n ]

AS SNAPSHOT OF source_database_nameAS SNAPSHOT OF source_database_name

[;][;]

其中,source_database_name 是源数据库,logical_file_name 是引用该文件时在 SQL Server 中使用的逻辑名称,os_file_name 是创建该文件时操作系统使用的路径和文件名,database_snapshot_name 是将数据库恢复到的快照的名称。Where source_**database_name is the source database, logical_file_name i s the logical name used in SQL Server when referencing the file, os_file_name is the path and file name used by the operating system when you create the file, and database_snapshot_name is the name of the snapshot to which you want to revert the database. For a full description of this syntax, see CREATE DATABASE (SQL Server Transact-SQL).

备注

创建数据库快照时,CREATE DATABASE 语句中不允许有日志文件、脱机文件、还原文件和不起作用的文件。When you create a database snapshot, log files, offline files, restoring files, and defunct files are not allowed in the CREATE DATABASE statement.

示例 (Transact-SQL)Examples (Transact-SQL)

备注

示例中使用的扩展名 .ss 是随意选择的。The .ss extension used in the examples is arbitrary.

本部分包含以下示例:This section contains the following examples:

A.A. 对 AdventureWorks 数据库创建快照Creating a snapshot on the AdventureWorks database

此示例对 AdventureWorks 数据库创建数据库快照。This example creates a database snapshot on the AdventureWorks database. 快照名称 AdventureWorks_dbss_1800及其稀疏文件的名称 AdventureWorks_data_1800.ss指明了创建时间 6 P.M.(1800 小时)。The snapshot name, AdventureWorks_dbss_1800, and the file name of its sparse file, AdventureWorks_data_1800.ss, indicate the creation time, 6 P.M (1800 hours).

CREATE DATABASE AdventureWorks_dbss1800 ON

( NAME = AdventureWorks, FILENAME =

'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Data\AdventureWorks_data_1800.ss' )

AS SNAPSHOT OF AdventureWorks;

GO

B.B. 对 Sales 数据库创建快照Creating a snapshot on the Sales database

此示例对 sales_snapshot1200数据库创建数据库快照 Sales 。This example creates a database snapshot, sales_snapshot1200, on the Sales database. This database was created in the example, "Creating a database that has filegroups," in CREATE DATABASE (SQL Server Transact-SQL).

--Creating sales_snapshot1200 as snapshot of the

--Sales database:

CREATE DATABASE sales_snapshot1200 ON

( NAME = SPri1_dat, FILENAME =

'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\data\SPri1dat_1200.ss'),

( NAME = SPri2_dat, FILENAME =

'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\data\SPri2dt_1200.ss'),

( NAME = SGrp1Fi1_dat, FILENAME =

'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\mssql\data\SG1Fi1dt_1200.ss'),

( NAME = SGrp1Fi2_dat, FILENAME =

'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\data\SG1Fi2dt_1200.ss'),

( NAME = SGrp2Fi1_dat, FILENAME =

'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\data\SG2Fi1dt_1200.ss'),

( NAME = SGrp2Fi2_dat, FILENAME =

'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\data\SG2Fi2dt_1200.ss')

AS SNAPSHOT OF Sales;

GO

相关任务Related Tasks

另请参阅See Also

创建mysql数据库快照_创建数据库快照 (Transact-SQL)相关推荐

  1. mysql 隔离级别 快照_「数据库架构」三分钟搞懂事务隔离级别和脏读

    重要要点 仅凭ACID或非ACID来思考,还需要知道数据库支持的隔离级别. 标榜为"最终一致"的某些数据库可能返回与任何时间点不一致的结果. 一些数据库提供的隔离级别比您要求的更高 ...

  2. maxvalue mysql自动分区_创建mysql表分区的方法

    创建 mysql 表分区的方法 我来给大家介绍一下 mysql 表分区创建与使用吧,希望对各位同学会有所帮助.表分区的测试使用,主要内容来自 于其他博客文章以及 mysql5.1 的参考手册. 表分区 ...

  3. jsp和mysql答辩_如何应对JSP连接MySQL数据库问题_网站数据库怎么连接到网页答辩问题...

    当您面临JSP连接MySQL数据库问题,你首先需要在MySQL数据库里创建一username表,表里面创建两个字符型的字段,字段名分别为:uid,pwd,然后插入几条测试数据. 以下用两种方式来实现J ...

  4. mysql数据库实体_关系型数据库中实体之间的关系

    关系型数据库实体间有三种关联关系:一对一,一对多,多对多. 一对一关系(1:1): 如果实体集(表)A 中的每一个实休(就是每行记录),在实体集B中只有一条数据与它对应, 反之实体集B 中的每一个实体 ...

  5. mysql 添加分区_创建,增加,删除mysql表分区

    1.测试添加分区和删除分区 ###添加删除range分区 (1)创建一个分区: CREATE TABLE titles ( emp_no      INT NOT NULL, title        ...

  6. mysql 数据透视_把数据库中的数据制作成Excel数据透视表

    如果我们在使用Excel的时候,需要把数据库中的数据制作成Excel数据透视表,我们该怎么操作呢?如果数据在数据库中,我们不用把数据导入到工作表中,我们可以直接以数据库的全部数据或者部分数据制作数据透 ...

  7. vb mysql存图片_如何用vb向sql数据库存取照片 最好有事例 谢谢

    展开全部 在VB中存62616964757a686964616fe78988e69d8331333231616638取数据库中的图片 2001-07-05· ·史美康 ··vbeden.com 一. ...

  8. mysql 图形插件_对我来说数据库图形化管理工具用这个足够了

    1. 前言 胖哥是一个有软件洁癖的人,能用现有的软件解决问题的绝不安装新的软件.Java后端开发主要跟数据库打交道,所以数据库图形化界面(GUI)是少不了的.通常图形化操作关系型数据库(RMDBS)大 ...

  9. sql文件导入mysql数据库出错_如何解决navicat导入sql文件出错的问题

    如何解决navicat导入sql文件出错的问题 发布时间:2020-11-11 17:05:39 来源:亿速云 阅读:120 作者:小新 这篇文章主要介绍了如何解决navicat导入sql文件出错的问 ...

最新文章

  1. Jacobian 和 Hessian 矩阵
  2. mysql 人名用什么类型_如何选择合适的MySQL数据类型
  3. php转换图片属性a,PHP 提取图片img标记中的任意属性
  4. Windows下svn服务器安装
  5. 怎样看出一个人有数学天赋?
  6. (已拿offer)2017腾讯暑期实习生从笔试到面试总结(附带华为、阿里面试经历)...
  7. Jupyter notebook:如何切换Python环境
  8. python找数字_python – 找到与给定数字最接近的数字
  9. Redis持久化 - 邱乘屹的个人技术博客
  10. c语言中随机排序函数,利用随机函数产生N个随机整数(20000以上),对这些数进行多种方法进行排序。 用C语言编程...
  11. CreateCompatibleDC 说明
  12. 解决Google和kaggle注册问题以及GitHub上项目的学习
  13. js中match函数的用法
  14. python sklearn库silhouette_score轮廓系数接口调用
  15. 电信联通“抱团”,资费有望降低
  16. Spring Boot 2 入门笔记(尚硅谷)
  17. 「 LaTeX 」写论文,参考文献编译错误,ERROR:Misplaced alignment tab character .
  18. 客户需求分析8个维度_常规数据分析的3个维度以及5个优化点,信息流投放参考...
  19. android端推送到底有多烦
  20. 期货开户交易贵在坚持

热门文章

  1. jdk安装遇到cab文件损坏问题
  2. 如何删除远程桌面连接历史记录
  3. 调制方法为SVPWM的三相T型三电平并网逆变器simulink模型
  4. CCNA1:网路基础、TCP/IP、OSI、IPv4、子网划分、数据封装
  5. 学生-课程数据库建表代码(三张表:学生表 课程表 选课表SC)
  6. samsung电容命名法则
  7. 亮剑“互联网+政务服务”,航天信息助力政府“最多跑一次”改革
  8. 使用显卡程序加速(opencl、cuda)
  9. 在CSDN的第一粒种子
  10. python模拟登录抖音_利用 mitmproxy 实现抖音 Cookie,设备 ID 获取 (一)