Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

move all the non-clustered indexes to another filegroup

Posted on 2004-09-29
7
791 Views
Last Modified: 2012-06-21
What is the easiest way to move the entire database's non-clustered indexes into another filegroup?
Thanks!
0
Comment
Question by:loveviolet
  • 5
7 Comments
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12184841
Script the current indexes, edit the script to point to the new file group, drop the indexes, then run the edited script.
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12184931
To script the indexes, open Enterprise Manager and drill down to the tables, and select all the tables you want to script the indexes of (Ctrl-A for all of them). Right-click on any selected table name and choose All Tasks/Generate SQL Script... to start the wizard. Click on the Formatting tab and clear the CREATE and DROP checkboxes (this is to script the table, not the indexes. Next, click the Options tab and set the "Script indexes" checkbox. Click OK and tell it where to save the script.

Open the script in Query Analyzer and hit Ctrl-H to open the replace function. Replace "ON [PRIMARY]" with "ON [INDEX_GROUP]" or whatever the name of your new file group is.
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12185058
There are several ways to deal with dropping the indexes. If you have zillions of tables, I'd go to SQLServerCentral.com and grab one of their Index-dropping stored procedures. If you have a manageable number, I'd make a copy of the create-index script, and modify it to make each command a drop (by copying and altering the same script, you ensure you're only dropping what you will be receating):

DROP INDEX TableName.IndexName
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Author Comment

by:loveviolet
ID: 12185127
Thanks for your answer.  Actually I need to move all the unique constraints as well, but I want to eliminate the clustered ones...  The SQL server's built in script will not differentiate clustered/nonclustered constraints.
0
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 250 total points
ID: 12185487
You can script the unique constraints by checking the box for "Script PRIMARY keys, FOREIGN keys, defaults, and check constaints", but this may require you to cut the parts of the generated script that you don't want. The same with clustered. At least it's easier to cut what you don't need than write what you do need from scratch.

For a little more sophisticated scripting, there is a "Smart Index Manipulation system" stored procedure code available at SQLServerCentral.com. It requires registration, but it's free. Here's a description:

Script Rating 4/5       Total number of votes [13]  By: psnipes
We are constantly having to drop indexes from tables while repopulating the data in the table. We then have to rebuild the indexes as they were before dropping them. This requires writing a custom drop and recreate index
script for each unique situation. If we try to write scripts ahead of time as soon as the indexing scheme changes on the table the scripts must be changed as well. This sp is part of a collection of five stored procedures I call the Smart Index Manipulation System. It allows you to drop indexes dynamically and then recreate them later just as they were before the drop. You can also keep a running history of your indexes as they change over time.
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12185702
Oh, another way to generate one script at a time is with Query Analyzer. F8 opens the Object Browser, and if you drill down to one level below tables, you can find some of the indexes and constraints (separate nodes) that you can right-click-drag & drop into the code window and it will let you choose Create or Drop scripts, which it will write for you. You can left-click-drag if you only want the index or constraint name.
0
 
LVL 34

Expert Comment

by:arbert
ID: 12186013
Also, think just using the CREATE INDEX script with the DROP_EXISTING clause.  It will be a little bit more efficient than dropping the current and recreating it.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question