[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

move all the non-clustered indexes to another filegroup

Posted on 2004-09-29
7
Medium Priority
?
796 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
[X]
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
  • 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
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 750 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

656 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