?
Solved

SQL Rebuild Index After Shrink?

Posted on 2013-12-18
6
Medium Priority
?
5,644 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 1000 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 1000 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

762 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