7

SQL SERVER - Rebuilding Index with Compression - SQL Authority with Pinal Dave

 2 years ago
source link: https://blog.sqlauthority.com/2021/09/01/sql-server-rebuilding-index-with-compression/?utm_campaign=sql-server-rebuilding-index-with-compression
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

SQL SERVER – Rebuilding Index with Compression

We can be Rebuilding Index with Compression even if it was originally not created with compressions. Let us learn how we can do it today. I had recently discussed with my client at Comprehensive Database Performance Health Check.

SQL SERVER - Rebuilding Index with Compression Index-with-Compression-800x345

We had an interesting situation at my client’s place. Where we had run few tests and found that we can use compressed indexes for better performance. The compressed index has the advantage of better storage and lesser read of pages while retrieving data from it.

Now if you have an index that was originally created without compression, you can still enable the compression when you rebuild the index. Here is the script for it.

ALTER TABLE Production.TransactionHistory REBUILD
WITH (DATA_COMPRESSION = ROW);

Now the script above is for the row compression, however, you can easily compress the page as well by running the following script.

ALTER TABLE Production.TransactionHistory REBUILD 
WITH (DATA_COMPRESSION = PAGE);

Now the question is which is better Page Compression or Row Compression? Well, there is not a simple answer to this question. As I mentioned earlier, you will have to test this entire scenario for your own environment. It is quite possible that you will find that compression itself is not recommended in your scenario at all. If you do not have time and energy for testing, I will say, just leave the default settings as it is.

Here are my few recent videos and I would like to know what is your feedback about them. Do not forget to subscribe SQL in Sixty Seconds series.

Reference: Pinal Dave (http://blog.SQLAuthority.com)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK