Solved

SQL Rebuild Index After Shrink?

Posted on 2013-12-18
6
4,191 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
  • 3
  • 2
6 Comments
 
LVL 39

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 39

Expert Comment

by:lcohan
ID: 39727878
Lot more about reindexing and maintenance at: http://ola.hallengren.com/
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now