script for compression automation on daily basis

  • I have partitioned my tables on a business date basis(365 partitions in a year). I want to do page compression on a daily basis of yesterday(D-1) data of all tables in a database. Any help on how to implement it ?? If you have any script please share.

  • How would you do this manually? If I said today, compress the partition from yesterday, what would you do? Likely you can get the code right and then look at how that changes to tomorrow? It's a simple parameter change. Make that part a script you generate.

    A simple idea is  use EXEC() to do this.

    declare @cmd  varchar(max)
    select @cmd = 'compress_partition name = ''' + @somename + datepart(day, getdate()) + ''' with myoptions'
    exec (@cmd)

  • Steve Jones - SSC Editor - Tuesday, September 12, 2017 7:42 AM

    How would you do this manually? If I said today, compress the partition from yesterday, what would you do? Likely you can get the code right and then look at how that changes to tomorrow? It's a simple parameter change. Make that part a script you generate.

    A simple idea is  use EXEC() to do this.

    declare @cmd  varchar(max)
    select @cmd = 'compress_partition name = ''' + @somename + datepart(day, getdate()) + ''' with myoptions'
    exec (@cmd)

    Now I am compressing like this.

    USE [DBNAME]

    ALTER TABLE [dbo].

    REBUILD PARTITION = 14 WITH(DATA_COMPRESSION = PAGE )

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply