Search This Blog

Wednesday, July 20, 2011

sql server best practices: database creation

when you create a new database in with the default options, sql server creates two files, the data file and the log file, in a single filegroup called PRIMARY. the files are created in the DATA sub-folder of the directory where you installed sql server unless you override the defaults (as you should). the state of the PRIMARY filegroup determines the state of the database

why this is bad: by only having one data file, user databases are stored in the same location as system databases. the majority of data changes occur in the the user databases. if the drive fails in the middle of a write operation, your data file becomes corrupt and all databases within become unusable. while having separate data files for your system and user databases avoids the previous situation, corruption to any file in the PRIMARY filegroup makes the database unusable.

what to do instead: minimally, all new databases should be created with two filegroups, two data files and a log file. the filegroups and the log file should all ideally be located on separate drives (which are hopefully RAID drives but more on best practices for RAID configurations for data log files in a future post). place one data file in the PRIMARY filegroup. this data file will contain the system databases and has a file extension of .mdf by convention. place the other data file in the second file group. this data file will contain user databases and has a file extension of .ndf by convention. change the default filegroup from PRIMARY to the second filegroup so new objects are created in the .ndf data file.