Monday, September 26, 2016

SQL Server - Database Files & Filegroup


Every SQL Server database has two operating system files: a data file and a log file. Data files contain data and objects such as tables, indexes, stored procedures, and views. Log files contain the information that is required to recover all transactions in the database. Data files can be grouped together in filegroups for allocation and administration purposes. 

Database Files 
SQL Server databases have three types of files, as following:

Primary

The primary data file contains the start-up information for the database and points to the other files in the database. User data and objects can be stored in this file or in secondary data files. Every database has one primary data file.

The recommended file name extension for primary data files is .mdf.

Secondary

Secondary data files are optional, are user-defined, and store user data. Secondary files can be used to spread data across multiple disks by putting each file on a different disk drive. Additionally, if a database exceeds the maximum size for a single Windows file, you can use secondary data files so the database can continue to grow.

The recommended file name extension for secondary data files is .ndf.

Transaction Log

The transaction log files hold the log information that is used to recover the database. There must be at least one log file for each database.

The recommended file name extension for transaction logs is .ldf.



Filegroups 


Primary Filegroup 

Every database has a PRIMARY Filegroup. This PRIMARY Filegroup contains System Files, Main Data File, Transaction Log File and optionally Secondary Data Files. When objects are created in the database without specifying which filegroup they belong to, they are assigned to the default filegroup. 

User-defined Filegroups 

User-defined Filegroups can be created to group data files together for administrative, data allocation, and placement purposes. 


No comments:

Post a Comment