SQL Server - 文件组,文件,备份,分区

Posted Niko12230

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL Server - 文件组,文件,备份,分区相关的知识,希望对你有一定的参考价值。

FileGroup:文件组,为逻辑划分;Files:文件,为实际文件,需要指定文件属于哪个文件组。

使用多个文件的有点:可以将磁盘I/O压力分散,提供按文件和文件组(按文件和文件组进行备份需要设置数据的恢复模式为Full)进行备份。

--创建文件组
USE [master]
GO
ALTER DATABASE [DWH_Optimizing] ADD FILEGROUP [DWH_Optimizing_1]
GO
ALTER DATABASE [DWH_Optimizing] ADD FILEGROUP [DWH_Optimizing_2]
GO
ALTER DATABASE [DWH_Optimizing] ADD FILEGROUP [DWH_Optimizing_3]
GO
ALTER DATABASE [DWH_Optimizing] ADD FILEGROUP [DWH_Optimizing_4]
GO

--创建文件
USE [master]
GO
ALTER DATABASE [DWH_Optimizing] ADD FILE ( NAME = NDWH_Optimizing_11, FILENAME = NE:\MSSQL11.BIS01\MSSQL\DATA\DWH_Optimizing_11.ndf , SIZE = 512000KB , FILEGROWTH = 50%) TO FILEGROUP [DWH_Optimizing_1]
GO
ALTER DATABASE [DWH_Optimizing] ADD FILE ( NAME = NDWH_Optimizing_12, FILENAME = NE:\MSSQL11.BIS01\MSSQL\DATA\DWH_Optimizing_12.ndf , SIZE = 512000KB , FILEGROWTH = 50%) TO FILEGROUP [DWH_Optimizing_1]
GO
ALTER DATABASE [DWH_Optimizing] ADD FILE ( NAME = NDWH_Optimizing_21, FILENAME = NE:\MSSQL11.BIS01\MSSQL\DATA\DWH_Optimizing_21.ndf , SIZE = 512000KB , FILEGROWTH = 50%) TO FILEGROUP [DWH_Optimizing_2]
GO
ALTER DATABASE [DWH_Optimizing] ADD FILE ( NAME = NDWH_Optimizing_22, FILENAME = NE:\MSSQL11.BIS01\MSSQL\DATA\DWH_Optimizing_22.ndf , SIZE = 512000KB , FILEGROWTH = 50%) TO FILEGROUP [DWH_Optimizing_2]
GO
ALTER DATABASE [DWH_Optimizing] ADD FILE ( NAME = NDWH_Optimizing_31, FILENAME = NE:\MSSQL11.BIS01\MSSQL\DATA\DWH_Optimizing_31.ndf , SIZE = 512000KB , FILEGROWTH = 50%) TO FILEGROUP [DWH_Optimizing_3]
GO
ALTER DATABASE [DWH_Optimizing] ADD FILE ( NAME = NDWH_Optimizing_32, FILENAME = NE:\MSSQL11.BIS01\MSSQL\DATA\DWH_Optimizing_32.ndf , SIZE = 512000KB , FILEGROWTH = 50%) TO FILEGROUP [DWH_Optimizing_3]
GO
ALTER DATABASE [DWH_Optimizing] ADD FILE ( NAME = NDWH_Optimizing_41, FILENAME = NE:\MSSQL11.BIS01\MSSQL\DATA\DWH_Optimizing_41.ndf , SIZE = 512000KB , FILEGROWTH = 50%) TO FILEGROUP [DWH_Optimizing_4]
GO
ALTER DATABASE [DWH_Optimizing] ADD FILE ( NAME = NDWH_Optimizing_42, FILENAME = NE:\MSSQL11.BIS01\MSSQL\DATA\DWH_Optimizing_42.ndf , SIZE = 512000KB , FILEGROWTH = 50%) TO FILEGROUP [DWH_Optimizing_4]
GO
ALTER DATABASE [DWH_Optimizing] MODIFY FILE ( NAME = NDWH_Optimizing_log, MAXSIZE = UNLIMITED)
GO

备份:完整备份,差异备份,文件、文件组和日志备份(需要设置数据的恢复模式为Full)

--文件组备份
BACKUP DATABASE [DWH_Optimizing] FILEGROUP = NDWH_Optimizing_1 TO  DISK = NF:\MSSQL11.BIS01\MSSQL\Backup\DWH_Optimizing.bak WITH NOFORMAT, NOINIT,  NAME = NDWH_Optimizing-Full Filegroup Backup, SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO

--文件备份
BACKUP DATABASE [DWH_Optimizing] FILE = NDWH_Optimizing_11 TO  DISK = NF:\MSSQL11.BIS01\MSSQL\Backup\DWH_Optimizing.bak WITH NOFORMAT, NOINIT,  NAME = NDWH_Optimizing-Full File Backup, SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO

--完整备份
BACKUP DATABASE [DWH_Optimizing] TO  DISK = NF:\MSSQL11.BIS01\MSSQL\Backup\DWH_Optimizing.bak WITH NOFORMAT, NOINIT,  NAME = NDWH_Optimizing-Full Database Backup, SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO

--差异备份
BACKUP DATABASE [DWH_Optimizing] TO  DISK = NF:\MSSQL11.BIS01\MSSQL\Backup\DWH_Optimizing.bak WITH  DIFFERENTIAL , NOFORMAT, NOINIT,  NAME = NDWH_Optimizing-Differential Database Backup, SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO

--事物日志备份
BACKUP LOG [DWH_Optimizing] TO  DISK = NF:\MSSQL11.BIS01\MSSQL\Backup\DWH_Optimizing.bak WITH NOFORMAT, NOINIT,  NAME = NDWH_Optimizing-Transaction Log  Backup, SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO

分区,可以将表按照某个字段进行分区

--创建分区函数
CREATE PARTITION FUNCTION [PF_BICompany](int) AS RANGE RIGHT FOR VALUES (2, 3, 4, 5)
GO

--创建分区架构
CREATE PARTITION SCHEME [PS_BICompany] AS PARTITION [PF_BICompany] TO ([DWH_Optimizing_1], [DWH_Optimizing_2], [DWH_Optimizing_3], [DWH_Optimizing_4], [PRIMARY])
GO

 

以上是关于SQL Server - 文件组,文件,备份,分区的主要内容,如果未能解决你的问题,请参考以下文章

SQL Server分区脚本备份

SQL Server使用文件组备份降低备份文件占用的存储空间

SQL SERVER 性能优化四: 创建分区表

SQL SERVER删除文件组和文件

SQL Server 数据分区管理

SQL Server 数据分区管理