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?>
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.