Share via

Why we use Filegroups? What are the benefits?

Rabia Kurnaz 386 Reputation points
2022-08-09T13:33:12.997+00:00

What are File Groups? Can you give an example of why we use it?

SQL Server | Other
0 comments No comments

Answer accepted by question author

  1. CathyJi-MSFT 22,426 Reputation points Microsoft External Staff
    2022-08-10T06:17:56.427+00:00

    Hi @Rabia Kurnaz ,

    What is Filegroup?

    In a database, a filegroup is a rational approach for grouping objects. Filegroups should not be confused with actual files (.mdf, .ddf, .ndf, .ldf, etc.). Per database, you can even have multiple filegroups.

    When to Create Filegroup? Or benefits of creating filegroup.

    • SQL Server accesses data using threads; each thread is responsible for retrieving or updating data on specific pages at specific locations on discs; if you have multiple filegroups and data is spread across the disc, SQL Server can take advantage of parallel threads, which improves database performance.
    • If you’ve had a join operation that involves multiple tables in a database, putting them all in one filegroup will keep SQL Server running in parallel (for the most part); however, putting the tables in different filegroups and placing them on different discs or luns will increase operational efficiency against strongly accessed tables in different file groups because SQL Server can use parallel threads.
    • While preparing or updating the database, your database performs poorly. Multiple threads can work together to retrieve data from different file groups at the same time.
    • You have quite a table with several years of data, but you are only using a few recent years of data; that’s very helpful when partitioning the table and indexes. It also makes it easier to archive data and avoids unnecessary scanning of records that are not currently important.
    • You have a large database, and full or disparity backup recovery times are unacceptable; if you discover database corruption of objects related to a specific filegroup, users could really restore just that file group to restore files quickly.

    Refer to this blog to get more information.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


2 additional answers

Sort by: Most helpful
  1. Erland Sommarskog 133.9K Reputation points MVP Volunteer Moderator
    2022-08-09T21:41:03.49+00:00

    I would say that the reasons that sreejukg give for filegroups are mainly a thing of the past. Often all disks are on the same SAN anyway.

    There can still be reason to use filegroups, though. Some people prefer to reserve the primary filegroup for the system tables and keep it small.

    You can also use filegroups to improve your restore times. That is, if you put less interesting archive tables on a different filegroup, you can opt to restore the database without that filegroup, or save that for later. This shortens the restore time for the important data.

    2 people found this answer helpful.
    0 comments No comments

  2. Sreeju Nair 12,761 Reputation points
    2022-08-09T14:13:25.34+00:00

    In general SQL Server database will have atleast two files, primary data file (.mdf) and log file (.ldf). The data file contains your tables, views, stored procedure etc. In addition to the data file and log file, you can have secondary data file (.ndf) files.

    Imagine your server has 6 disks, instead of using one disk to store your database, where you will have to read and write to the same disk, for a high transaction database, it will have I/O issues. To solve this, you can have your database in to multiple files (where files represent the physical location where the data is stored) and file groups (that is a logical grouping of files. The files can be in diffrent disks thus your database will make the best of of your disks.

    Read more below.
    https://learn.microsoft.com/en-us/sql/relational-databases/databases/database-files-and-filegroups?view=sql-server-ver16

    Hope this helps

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.