Solved

SQL Rebuild Index After Shrink?

Posted on 2013-12-18
6
5,009 Views
Last Modified: 2013-12-20
Hello:

I read somewhere that it is a good idea to run a rebuild of the index after shrinking a database.  Is that correct?

Is "rebuild" the same thing as "reorganize"?

How can you run rebuild index against an entire database and just individual tables at a time?

TBSupport
0
Comment
Question by:TBSupport
[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
  • 3
  • 2
6 Comments
 
LVL 40

Accepted Solution

by:
lcohan earned 250 total points
ID: 39727858
Why would you shrink a database first of all??
You should never do that in my opinion (and others) and to get T-log under control you need at least a daily backup full+t-log to be done.

http://www.brentozar.com/archive/2009/08/stop-shrinking-your-database-files-seriously-now/

Rebuild is NOT the same as Reorganize and to reindex all tables in a DB you can use a SQL Script like:

http://www.mssqltips.com/sqlservertip/1367/sql-server-script-to-rebuild-all-indexes-for-all-tables-and-all-databases/

In SQL Enterprise Edition you can REBUILD an index with ONLINE=ON therefor not locking the table.
0
 
LVL 13

Assisted Solution

by:magarity
magarity earned 250 total points
ID: 39727875
So let's assume you mistakely shrank your database already (see other's post about not doing it in the first place).  There are two shrink options as I recall, one that simply lops off trailing empty space and a nuclear option that reorganizes so that all internal empty fragments are filled first then the trailing space lopped off.  
If you did the first, then you can probably go either way and rebuild or not.  Safer to just go ahead and do so.  If you did the second, your database is in pain and you need to rebuild all indexes if just to give the system some breathing space.  Reuild them again after some modest activity has taken place like in a day or so. Then read all the articles linked in the article linked by lcohan.
0
 
LVL 40

Expert Comment

by:lcohan
ID: 39727878
Lot more about reindexing and maintenance at: http://ola.hallengren.com/
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 13

Expert Comment

by:magarity
ID: 39727884
PS - here's a handy script that will rebuild all indexes (it may take some time to execute): http://www.mssqltips.com/sqlservertip/1367/sql-server-script-to-rebuild-all-indexes-for-all-tables-and-all-databases/
0
 
LVL 1

Author Comment

by:TBSupport
ID: 39728058
Whether shrink is used or not, I need to reduce the amount of space being taken up on a server by a 10GB database.  There is empty space in the database.  I'm trying to get rid of that empty space, reduce the database size, and therefore free up more space on the server.

If shrink is not the correct option, then please tell me the alternative, based on what I have outlined as my needs.

Much appreciated!

TBSupport
0
 
LVL 13

Expert Comment

by:magarity
ID: 39728095
I know corporate internal pricing for storage can be out of touch with reality but it's impressive that you're in capacity trouble at 10GB and your only recourse is shrinking the db. Have you asked your server administrator to grow the partition and been turned down?
You've done all the usual transaction log backup and removal?
You can also look at removing unneeded non-clustered indexes or moving them to another partition.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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