SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Automate Data Compression


Automate Data Compression

Author
Message
Tara-1044200
Tara-1044200
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3301 Visits: 3077
I would like to automate the compression job for every week end by filtering on newly created tables/indexes with more than 10gb size, also would like to run on all tables in the server for the first time. Is there a script already on this forum to share, appreacite your help.

Here are the commands i will be using on a SQL Server 2008R2 version, Thanks


ALTER TABLE dbo.tabEMP REBUILD PARTITION = ALL WITH (DATA_COMPRESSION=ROW);
----------------------------------------------------------------------------------------------------
ALTER INDEX [index_main] ON [dbo].[tabEMP] REBUILD WITH (DATA_COMPRESSION=ROW);
Bill (DBAOnTheGo)
Bill (DBAOnTheGo)
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1221 Visits: 599
I do not have an automated function, however... This may work until you build one or someone assists with one. Make sure and set results to text.

For tables:

sp_msforeachdb @command1 ='use ?
if ''?'' <> ''master'' and ''?'' <> ''model'' and ''?'' <> ''msdb'' and ''?'' <> ''tempdb''
begin
Select ''USE '' + (Select DB_name())
SELECT DISTINCT ''ALTER TABLE ['' + sys.schemas.name + ''].['' + sys.tables.name+ ''] REBUILD PARTITION = ALL WITH (DATA_COMPRESSION = PAGE, ONLINE = Off);''
FROM
sys.tables
INNER JOIN sys.partitions ON sys.partitions.object_id = sys.tables.object_id
INNER JOIN sys.schemas ON sys.tables.schema_id = sys.schemas.SCHEMA_ID
select ''GO''
end'



For indexes:

sp_msforeachdb @command1 ='use ?
if ''?'' <> ''master'' and ''?'' <> ''model'' and ''?'' <> ''msdb'' and ''?'' <> ''tempdb''
begin
Select ''USE '' + (Select DB_name())
SELECT DISTINCT ''ALTER INDEX ['' + sys.indexes.name + ''] ON ['' + sys.schemas.name + ''].['' + sys.tables.name+ ''] REBUILD PARTITION = ALL WITH ( STATISTICS_NORECOMPUTE = OFF, ONLINE = ON, SORT_IN_TEMPDB = OFF, DATA_COMPRESSION = PAGE )''
FROM
sys.indexes
INNER JOIN sys.tables ON sys.indexes.object_id = sys.tables.object_id
INNER JOIN sys.schemas ON sys.tables.schema_id = sys.schemas.schema_id
INNER JOIN sys.partitions ON sys.partitions.object_id = sys.indexes.object_id AND sys.partitions.index_id = sys.indexes.index_id
where sys.partitions.data_compression_desc <> ''PAGE''
select ''GO''
END'



.
rix
rix
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 73
maybe this for the size requirement:


WHERE
(convert(varchar,((sys.dm_db_partition_stats.used_page_count*8)/1048576))>10)


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search