SQL SERVER – Create Multiple Filegroup For Single Database

I am elated to receive hundreds of emails every day from my readers. My tight work schedule refrains me from answering all your questions, but I do try my best to entertain them whenever I can. Today’s post revolves around a question I received a number of times last year but never blogged on it. On positive side, you are reading about that interesting subject today.

The question is – How to create multiple filegroup for any database?

To find solution to this query, we will go through the following four cases.

1) Creating New Database

a) Using T-SQL
b) Using SSMS

2) Updating Existing Database and Adding Filegroup

a) Using T-SQL
b) Using SSMS

Solarwinds

Let us go over each of the cases one by one.

1) Creating New Database
a) Using T-SQL

CREATE DATABASE [FGTest] ON  PRIMARY
( NAME = N'FGTest',
FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\FGTest.mdf' ,
SIZE = 3072KB , FILEGROWTH = 1024KB ),
FILEGROUP [Secondary] ( NAME = N'FGTest_2',
FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\FGTest_2.ndf' ,
SIZE = 3072KB , FILEGROWTH = 1024KB )
LOG ON
( NAME = N'FGTest_log',
FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\FGTest_log.ldf' ,
SIZE = 1024KB , FILEGROWTH = 10%)
GO

b) Using SSMS

SQL SERVER - Create Multiple Filegroup For Single Database ndf1

SQL SERVER - Create Multiple Filegroup For Single Database ndf2

SQL SERVER - Create Multiple Filegroup For Single Database ndf3

SQL SERVER - Create Multiple Filegroup For Single Database ndf4

2) Updating Existing Database and Adding Filegroup

Updating existing database is much simpler compared with adding filegroup to new database. Let us take a look at how quickly it can be completed in a few simple steps.

a) Using T-SQL
We will add a Third filegroup to the same database where we added secondary filegroup in the above example.

USE [master] GO
ALTER DATABASE [FGTest] ADD FILEGROUP [Third] GO

b) Using SSMS
Right click on the database and go to properties and filegroup. Add new filegroup by simply adding name.

SQL SERVER - Create Multiple Filegroup For Single Database ndf5

I encourage all my readers to keep mailing me send in your questions and doubts. I will certainly take them up at some point of time.

Reference : Pinal Dave (https://blog.sqlauthority.com)

Solarwinds
,
Previous Post
SQL SERVER – Difference Between Candidate Keys and Primary Key
Next Post
SQL SERVER – List All Objects Created on All Filegroups in Database

Related Posts

42 Comments. Leave new

  • Hello Pinal Dev,
    How to move a existing table from one file group to another file group. Please share your valuable feedback for the same.
    Thank you,
    G Arunagiri

    Reply

Leave a Reply

Menu