以下示例在 SQL Server 實例上創建了一個數據庫。該數據庫包括一個主數據文件、一個用戶定義文件組和一個日志文件。主數據文件在主文件組中,而用戶定義文件組包含兩個次要數據文件。ALTER DATABASE 語句將用戶定義文件組指定為默認文件組。然后通過指定用戶定義文件組來創建表。
USE master; GO -- Create the database with the default data -- filegroup and a log file. Specify the -- growth increment and the max size for the -- primary data file. CREATE DATABASE MyDB ON PRIMARY( NAME='MyDB_Primary',FILENAME='c:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\data\MyDB_Prm.mdf',SIZE=4MB,MAXSIZE=10MB,FILEGROWTH=1MB), FILEGROUP MyDB_FG1( NAME = 'MyDB_FG1_Dat1',FILENAME ='c:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\data\MyDB_FG1_1.ndf',SIZE = 1MB,MAXSIZE=10MB,FILEGROWTH=1MB),( NAME = 'MyDB_FG1_Dat2',FILENAME ='c:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\data\MyDB_FG1_2.ndf',SIZE = 1MB,MAXSIZE=10MB,FILEGROWTH=1MB) LOG ON( NAME='MyDB_log',FILENAME ='c:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\data\MyDB.ldf',SIZE=1MB,MAXSIZE=10MB,FILEGROWTH=1MB); GO ALTER DATABASE MyDB MODIFY FILEGROUP MyDB_FG1 DEFAULT; GO-- Create a table in the user-defined filegroup. USE MyDB; CREATE TABLE MyTable( cola int PRIMARY KEY,colb char(8) ) ON MyDB_FG1; GO
?