Need help?

Our experts have had an average response time of 13.14 minutes in February 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

Move table to another filegroup with ease

by | Nov 1, 2020

Eager to move a table to another filegroup? We can help you with it.

Here at Bobcares, we have seen several such database-related errors as part of our Server Management Services for web hosts and online service providers.

Today we will take a look at how we can move the table into another filegroup.

 

Why moving a table to another filegroup is necessary

Sometimes it is very necessary to move the SQL Server tables between two filegroups or create a copy of a table in a different filegroup. The main purpose of having a copy of a table in a different filegroup could be for archiving historical data, disk space issues, using a copy of the table for reporting or for testing purposes.

For instance, a database located on D drive is grown large in size and the drive is running out of space. There are other drives on the server that has enough free disk space. So here, the immediate and easiest solution would be to move the large tables from D drive to a different drive where there is enough space to make some room for the database.

 

How we move the table to another filegroup

Now let’s see how our Support Engineers assist our customers in moving a table.

1. First, identify the large tables that we will be moving to another filegroup placed on drive E.
2. Now, create a new filegroup on disk E. In case, if you already have a filegroup on this drive then you can use it.
3. Then add a data file to this newly created filegroup.
4. Drop the clustered index from the table that has been identified for the movement. Then recreate it for another filegroup.
5. Finally, create a clustered index on the same table.

 

Move a table to a different Filegroup using T-SQL codes

You can also move the table from one filegroup to another filegroup by dropping and recreating the clustered indexes. Here are the T-SQL codes that will move the complete table from filegroup1 to filegroup2.

ALTER TABLE TAB1 DROP CONSTRAINT PK_TAB1 WITH (MOVE TO TEST_DATA_2)
GO
ALTER TABLE TAB1 ADD CONSTRAINT PK_TAB1 PRIMARY KEY(TAB1_ID)
GO

where TAB1 is the table name, PK_TAB1 is the clustered index key and TEST_DATA_2 is the target filegroup. However, it isn’t necessary to create another filegroup into a separate disk. You can use this method if you are moving a table from one filegroup to another filegroup irrespective of the filegroup drives.

In case, if your table doesn’t have a clustering index, you can still move the table by creating a clustering index and then follow the same process to move it.

 

Moving an existing index using Table Designer

1. First, in Object Explorer, click on the plus sign to expand the database that contains the table containing the index that you want to move.
2. Next, click the plus sign to expand the Tables folder.
3. Now right-click on the table containing the index that you want to move and select Design.
4. Click Indexes/Keys on the Table Designer menu.
5. Now select the index that you wish to move.
6. Expand Data Space Specification in the main grid.
7. Then select the Filegroup or Partition Scheme Name and select from the list the filegroup or partition scheme to where you want to move the index.
8. After that, click on the Close button.
9. Finally, on the File menu select Savetable_name.

[Need any further assistance with Database queries? – We are here to help you]

 

Conclusion

In short, moving a table to another filegroup can be done manually, or by using T-SQL codes. It can also be done using a Table designer. Today, we saw how our Support Engineers do 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

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

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

Categories

Tags

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

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid

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