Rank Index Contention with sys.dm_db_index_operational_stats
Oct 22, 2026 / · 7 min read · sql server sys.dm_db_index_operational_stats sys.indexes sys.dm_os_wait_stats sys.dm_db_index_usage_stats lock contention row locks blocking indexes performance tuning dmv tsql ·Once sys.dm_os_wait_stats points to locking, the next question is which index the waits belong to. The script below reads sys.dm_db_index_operational_stats for the current database and ranks each user-table index by its number of row-lock waits. Next to each count it returns the share of row-lock requests that had to …
Read MoreApply Row and Page Compression to Tables and Indexes
Jun 30, 2026 / · 11 min read · sql server data compression sys.dm_db_index_physical_stats sys.partitions sys.indexes sys.objects sys.schemas row compression page compression index maintenance maintenance scripts ·Heaps and indexes that were never compressed keep occupying full-size pages, and nothing in a default database flags them. sys.dm_db_index_physical_stats joined to sys.partitions lists the uncompressed heaps and indexes above a size threshold, and the script below turns that list into ready-to-review ALTER INDEX ... …
Read Moresysindexes vs sys.indexes: Legacy and Modern Catalog Views
Plenty of SQL Server scripts still in circulation read rowcnt and dpages straight out of sysindexes — a habit inherited from SQL Server 2000, where that table was the canonical place to find row counts and page totals. The object survives only as the sys.sysindexes compatibility view, is flagged for removal, and …
Read MoreSQL Server Catalog Views: sys.tables, sys.indexes, sys.objects
Jun 14, 2026 / · 9 min read · sql server catalog views system tables metadata sys.tables sys.indexes sys.objects sys.schemas sys.partitions sys.columns sys.index_columns database structure scripts ·Three catalog views, sys.objects, sys.tables, and sys.indexes, answer most day-to-day questions about what a database contains. This script joins them with sys.schemas and sys.partitions into one inventory: every user table, its schema, its dates, its row count, and each index defined on it. The row count comes from a …
Read MoreSQL Server DBCC SHRINKDATABASE: When and When Not to Shrink
A one-time data load doubled a data file overnight, the load is done, the rows are deleted, and the file is now mostly empty space. The reflex — reach for DBCC SHRINKDATABASE and give the disk back — is a common way to hurt performance without meaning to. This post explains what shrinking does to your indexes, when it …
Read MoreDBCC DBREINDEX vs ALTER INDEX REBUILD in SQL Server
Open the SQL Agent job history on an instance that has been running for a decade and you will still find DBCC DBREINDEX in a nightly maintenance step, quietly doing its job. It works — which is exactly why nobody has touched it. But it has been deprecated for the better part of twenty years, it locks tables it does not …
Read MoreSQL Server Duplicate and Overlapping Index Detection Script
Duplicate and overlapping indexes waste storage, slow down every write, and split optimizer statistics across redundant copies. This T-SQL script compares each non-heap index in the current database on its first sixteen key columns and surfaces any pair of indexes that overlap, giving the DBA a short list of cleanup …
Read MoreKnowing how much space each table and each index consumes is the foundation of capacity planning, archive policy, and index cleanup decisions on any SQL Server instance. This T-SQL script reads the partition-level storage statistics out of sys.dm_db_partition_stats and reports the size of every index on a user table — …
Read MoreSQL Server Identify Heap Tables Without Clustered Indexes
May 15, 2026 / · 9 min read · sql server heap tables sys.tables sys.indexes sys.dm_db_index_physical_stats sys.allocation_units sys.partitions performance database administration sql scripts ·A heap table — a table with no clustered index — stores rows in no particular order, forces full table scans for most non-indexed queries, and accumulates forwarded records every time an UPDATE causes a row to outgrow its page. This script queries sys.tables, sys.indexes, sys.partitions, sys.allocation_units, and …
Read MoreSQL Server: Find Tables Without Primary Keys
Apr 16, 2026 / · 7 min read · sql server primary keys database structure heap tables sql scripts schema audit performance sys.tables sys.dm_db_index_physical_stats sys.indexes sys.key_constraints sys.partitions ·Tables without primary keys are heap structures with no guaranteed row ordering and no unique row identifier. They cause full table scans in queries that could use seeks, slow down DELETE and UPDATE operations, and are incompatible with SQL Server replication and Change Data Capture. This script finds every user table …
Read More