DECLARE tbl_compression CURSOR FOR SELECT o.name,sum(ps.row_count) as row_count FROM sys.partitions SP INNER JOIN sys.tables ST ON st.object_id = sp.object_id INNER JOIN sys.objects o on o.object_id = ST.object_id INNER JOIN sys.dm_db_partition_stats ps on o.object_id = ps.object_id WHERE SP.data_compression=0 --OR SP.data_compression>0 GROUP BY SP.object_id,o.schema_id, o.name ORDER BY o.name OPEN tbl_compression FETCH NEXT FROM tbl_compression INTO @tbl_name,@row_count WHILE @@FETCH_STATUS=0 BEGIN PRINT ('-- tablo_Adi: '+@tbl_name+' row_count: '+convert(varchar(50),@row_count)) SET @sql='ALTER TABLE [dbo].['+@tbl_name+'] REBUILD PARTITION = ALL WITH (DATA_COMPRESSION = PAGE,MAXDOP=4); GO PRINT'''+@tbl_name+' BİTTİ''' PRINT (@sql) --EXECUTE(@sql) FETCH NEXT FROM tbl_compression INTO @tbl_name,@row_count END CLOSE tbl_compression DEALLOCATE tbl_compression