Bobcares

Add file and filegroup SQL server | How to?

by | Oct 27, 2022

Follow the Simple article on how to Add file and filegroup SQL server by our Microsoft SQL Server Support Services. Bobcares offers solutions to every query that comes our way.

Using SQL Server to add files and filegroup to a database

Add file and filegroup SQL server

Access to Object Explorer. From the SQL Server Database Engine Connect to an instance and next expand that Database instance.

 

Now Right-click the database to add the files. Further, click Properties.

 

In the Database Properties dialog box. Select the Files page.

 

Click Add To update a data or transaction log file.

 

Enter a logical name for the file in the Database files grid. The file name should be unique within the database.

 

Select the file type, data, or log.

 

For a data file, select the filegroup in which the file should be included from the list or select <new filegroup> to create a new filegroup. Note that Transaction logs cannot be put in filegroups.

 

Specify the initial size of the file. Make the data file as large as possible that is based on the maximum amount of data.

 

To specify how the file should grow. Click (…) in the Autogrowth column. Select from the following options:

 
  • To allow the selected file to grow more data space as required. Select the check box of Enable Autogrowth.
 
  • To specify, the file should grow by fixed increments. Choose In Megabytes and also specify a value.
 
  • The file will grow by a percentage of the current file size. Select In Percent value with the specification.
 

To specify the maximum file size limit. Select from the following options:

 
  • Specify the maximum size file. Select Restricted File Growth size MB and specify a value.
 
  • Allow for the file to grow maximum as required. Select Unrestricted File Growth.
 
  • To prevent the file from growing, you need to select clear the Enable Autogrowth check box. However, the size mentioned in the file will not grow beyond the value specified in the Initial Size MB column.
 

Specify the path for the file location and click OK.

 

Using Transact-SQL

 

To add data or log files to the database

 

1. Connect to the Database Engine.

 

2. From the Standard bar, click New Query.

 

3. Copy and paste the below example into the query window and click Execute option. In this example, it adds a filegroup with two files to a database. The example creates the filegroup Test1FG1 in the AdventureWorks20 database and adds two 5-MB files to the filegroup.

 

SQL

USE master
GO
ALTER DATABASE AdventureWorks20
ADD FILEGROUP Test1FG1;
GO
ALTER DATABASE AdventureWorks20 
ADD FILE 
(
    NAME = test1dat3,
    FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\t1dat3.ndf',
    SIZE = 5MB,
    MAXSIZE = 100MB,
    FILEGROWTH = 5MB
),
(
    NAME = test1dat4,
    FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\t1dat4.ndf',
    SIZE = 5MB,
    MAXSIZE = 100MB,
    FILEGROWTH = 5MB
)
TO FILEGROUP Test1FG1;
GO
     

    Following this, the SQL Server database will have two operating system files. i.e: the data file, and the log file.

     

    The data file will hold the actual data in the database. As well as the objects like indexes, tables, views, and stored procedures. The log file contains the information required to recover all transactions in the database.

     

    When a database is created with the default options, then both of these files will create. These files will be created in the primary filegroup. This filegroup contains the primary data file and any secondary files will not be put into other filegroups. Hence the primary filegroup is the default filegroup.

     

    Similarly, when you create multiple data files. You will have the option of grouping into a user-defined filegroup. This allows to group files logically within their own filegroup that was created. Accordingly, the Database objects will remain within the primary filegroup.

     

    View the Filegroups

     

    The filegroups can be viewed for a given database by querying the sys.filegroups catalog view.

     

    Example:

    USE Solutions;
    SELECT name, type_desc
    FROM sys.filegroups;
     

    Result:

    name                  type_desc     
    --------------------  --------------
    PRIMARY               ROWS_FILEGROUP
    Solutions1Filegroup1  ROWS_FILEGROUP
    
     

    You can even use an asterisk (*) key to return all rows if needed.

     

    [Looking for a solution to another query? We are just a click away.]

     

    Conclusion

    To conclude, This article shows how to create a user-defined filegroup and add some data files to it.

     

    PREVENT YOUR SERVER FROM CRASHING!

    Never again lose customers to poor server speed! Let us help you.

    Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

    GET STARTED

    0 Comments

    Submit a Comment

    Your email address will not be published. Required fields are marked *

    Never again lose customers to poor
    server speed! Let us help you.

    Privacy Preference Center

    Necessary

    Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

    PHPSESSID - Preserves user session state across page requests.

    gdpr[consent_types] - Used to store user consents.

    gdpr[allowed_cookies] - Used to store user allowed cookies.

    PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
    PHPSESSID
    WHMCSpKDlPzh2chML

    Statistics

    Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

    _ga - Preserves user session state across page requests.

    _gat - Used by Google Analytics to throttle request rate

    _gid - Registers a unique ID that is used to generate statistical data on how you use the website.

    smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

    _ga, _gat, _gid
    _ga, _gat, _gid
    smartlookCookie
    _clck, _clsk, CLID, ANONCHK, MR, MUID, SM

    Marketing

    Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

    IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

    test_cookie - Used to check if the user's browser supports cookies.

    1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

    NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

    DV - Google ad personalisation

    _reb2bgeo - The visitor's geographical location

    _reb2bloaded - Whether or not the script loaded for the visitor

    _reb2bref - The referring URL for the visit

    _reb2bsessionID - The visitor's RB2B session ID

    _reb2buid - The visitor's RB2B user ID

    IDE, test_cookie, 1P_JAR, NID, DV, NID
    IDE, test_cookie
    1P_JAR, NID, DV
    NID
    hblid
    _reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

    Security

    These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

    SID, APISID, HSID, NID, PREF
    SID, APISID, HSID, NID, PREF