Query all table data and index compression

前端 未结 4 1667
星月不相逢
星月不相逢 2021-02-04 03:26

Does anyone happen to have a generic SQL statement that\'ll list all of the tables and indexes in a database, along with their current compression setting, for each partition?

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-04 04:13

    These answers are all decent and work. Since I embellished it a bit for my work, I figured is was about time for to contribute back a bit. This query adds the schema from Jason's answer (which I needed). and it also sorts out some of the join issues and combines the results into a pretty simple summary.

    -- Returns user tables and indexes in a DB and their Compression state
    select s.name [Schema], t.name [Table], i.name [Index], p.data_compression_desc Compression
         , case when p.index_id in (0, 1) then 'Table' else 'Index' end CompressionObject
      from sys.tables t
      join sys.schemas s on t.schema_id = s.schema_id
      join sys.indexes i on t.object_id = i.object_id
      join sys.partitions p on (i.object_id = p.object_id and i.index_id = p.index_id)
    where t.type = 'U'
    order by 1, 2, p.index_id, 3
    

    I used this as a "work list" to generate scripts to compress everything since I just lift-shift the db into an Azure VM and wanting to reduce IOPS to improve perf. Hope this helps somebody out there.

提交回复
热议问题