可以在建立数据库时候创建 如:
CREATE DATABASE MyDB
ON PRIMARY --主文件组和主要数据文件
( NAME='MyDB_Primary',
FILENAME= 'c:\MyDB_Prm.mdf'),
FILEGROUP MyDB_FG1 --用户定义文件组1
( NAME = 'MyDB_FG1_Dat1',
FILENAME = 'c:\MyDB_FG1_1.ndf'), --次要数据文件1
( NAME = 'MyDB_FG1_Dat2',
FILENAME = 'd:\MyDB_FG1_2.ndf'), --次要数据文件2
FILEGROUP MyDB_FG2 --用户定义文件组2
( NAME = 'MyDB_FG1_Dat',
FILENAME = 'e:\MyDB_FG2.ndf') --次要数据文件
LOG ON --日志文件
( NAME='MyDB_log',
FILENAME ='d:\MyDB.ldf')
GO
下例在示例 A 中所创建的 Test1 数据库中创建一个文件组,并将两个 5 MB 的文件添加到该文件组。
USE master
GO
ALTER DATABASE Test1
ADD FILEGROUP Test1FG1
GO
ALTER DATABASE Test1
ADD FILE
( NAME = test1dat3,
FILENAME = 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\t1dat3.ndf',
SIZE = 5MB,
MAXSIZE = 100MB,
FILEGROWTH = 5MB),
( NAME = test1dat4,
FILENAME = 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\t1dat4.ndf',
SIZE = 5MB,
MAXSIZE = 100MB,
FILEGROWTH = 5MB)
TO FILEGROUP Test1FG1
F. 使用文件组创建数据库
下例使用三个文件组创建名为 sales 的数据库:
主文件组包含文件 Spri1_dat 和 Spri2_dat。指定这些文件的 FILEGROWTH 增量为 15%。
名为 SalesGroup1 的文件组包含文件 SGrp1Fi1 和 SGrp1Fi2。
名为 SalesGroup2 的文件组包含文件 SGrp2Fi1 和 SGrp2Fi2。
CREATE DATABASE Sales
ON PRIMARY
( NAME = SPri1_dat,
FILENAME = 'c:\program files\microsoft sql server\mssql\data\SPri1dat.mdf',
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 15% ),
( NAME = SPri2_dat,
FILENAME = 'c:\program files\microsoft sql server\mssql\data\SPri2dt.ndf',
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 15% ),
FILEGROUP SalesGroup1
( NAME = SGrp1Fi1_dat,
FILENAME = 'c:\program files\microsoft sql server\mssql\data\SG1Fi1dt.ndf',
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 5 ),
( NAME = SGrp1Fi2_dat,
FILENAME = 'c:\program files\microsoft sql server\mssql\data\SG1Fi2dt.ndf',
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 5 ),
FILEGROUP SalesGroup2
( NAME = SGrp2Fi1_dat,
FILENAME = 'c:\program files\microsoft sql server\mssql\data\SG2Fi1dt.ndf',
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 5 ),
( NAME = SGrp2Fi2_dat,
FILENAME = 'c:\program files\microsoft sql server\mssql\data\SG2Fi2dt.ndf',
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 5 )
LOG ON
( NAME = 'Sales_log',
FILENAME = 'c:\program files\microsoft sql server\mssql\data\salelog.ldf',
SIZE = 5MB,
MAXSIZE = 25MB,
FILEGROWTH = 5MB )
GO