{"id":2842,"date":"2015-11-10T04:47:35","date_gmt":"2015-11-10T09:47:35","guid":{"rendered":"https:\/\/academy.sqlbak.com\/?p=2842"},"modified":"2020-02-07T10:32:13","modified_gmt":"2020-02-07T15:32:13","slug":"database-files","status":"publish","type":"post","link":"https:\/\/academy.sqlbak.com\/database-files\/","title":{"rendered":"Database Files"},"content":{"rendered":"
Every database of\u00a0SQL Server at least has a log file and data file. Log files contain all information that is necessary to restore transactions in the database. Data files contain data and objects (indexes, tables, etc.).<\/p>\n
There are three types of database files in SQL Server:<\/p>\n
These name extensions (*.mdf, *.ndf and *.ldf) in SQL Server are not necessary, but they help us to discern\u00a0the types of data files.<\/p>\n
All files have logical and physical names. Physical file name is a path to the data file on disk. Logical name\u00a0is a short alias that refer to the physical file. Here’s how it looks:<\/p>\n
ALTER DATABASE<\/span> Test\r\nMODIFY FILE<\/span>\r\nNAME = NameTest - (logical file name)<\/span>\r\nFILENAME<\/span> = 'C:\\NameTest.mdf'<\/span> - (physical file name)<\/span><\/pre>\nData File Pages<\/h2>\n
The disk space allocated to data file in SQL Server is logically divided into pages. The pages are numbered sequentially starting with zero. Because every file has its own ID number, page identification requires the page number and the file ID. The first page in each file is a file header and the following few pages contain system information. Database boot page (contains database attributes) is stored in the first log file and in the primary data file.<\/p>\n
<\/p>\n
Database File Size<\/h2>\n
Each file grows by growth increments, as defined by user. File size increases every time it is filled with information. It is also necessary to specify the maximum file size, otherwise the file will grow until\u00a0it has used all free space on the disk.<\/p>\n
How to Backup a Database File<\/h2>\n
You can backup a single database file named ‘DataFile’ using the following\u00a0Transact-SQL<\/strong> command:<\/p>\nBACKUP DATABASE<\/span>\u00a0Test\r\nFILE<\/span> = 'DataFile'<\/span> TO DISK<\/span> = 'D:\\DataFile.bak'<\/span>;<\/pre>\nThe other way to backup a database file is to use\u00a0SQL Server Management Studio (SSMS):\u00a0<\/strong><\/p>\n\n- Right click on the database where the filegroup you want to backup is located<\/li>\n
- Select “Tasks”, then “Back up…”<\/li>\n
- Select \u00a0the backup type (“Full” or “Differential”)<\/li>\n
- Select “Files and filegroups”<\/li>\n
- Choose file and click “OK”\u00a0(It is possible to select one or more individual files, or select a filegroup to automatically choose all the files in that filegroup)
\n<\/li>\n - Add backup destination<\/li>\n
- Click “OK”<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"
Every database of\u00a0SQL Server at least has a log file and data file. Log files contain all information that is necessary to restore transactions in the database. Data files contain data and objects (indexes, tables, etc.).<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[157],"tags":[],"yoast_head":"\n
Database Files - Sql Server Backup Academy<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n