Query all table data and index compression

前端 未结 4 1670
星月不相逢
星月不相逢 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 03:55

    This should do the job, test it for a small subset to be sure it gives you what you need

    SELECT DISTINCT s.name [Schema], t.name [Table], i.name [Index Name], p.partition_number, p.data_compression_desc
    -- uncommenting the below line will give you dupes
    --, p.index_id
    FROM sys.schemas s
    INNER JOIN sys.tables t
        ON s.schema_id = t.schema_id
        INNER JOIN sys.indexes i
            ON t.object_id = i.object_id
        INNER JOIN sys.partitions p
            ON t.object_id = p.object_id
    ORDER BY s.name, t.name
    

    The reason you are probably getting dupes is because you have multiple partition records per table, e.g. multiple index_id, see this MSDN article for clarification on what the index_id's mean. Adding a DISTINCT should solve the problem of the dupes

提交回复
热议问题