Skip to content

Clive Roberts

SQL Server DBA

Menu
  • Setup
  • Performance
  • Health Check
  • Troubleshooting
  • T-SQL
  • Patches
  • News
  • Audit
  • Projects

Category: Performance

Query Store Capture Mode

November 15, 2026
| No Comments
| Performance, Question of the Day, SQL Server
Query Store Capture Mode: the T-SQL from this post in SQL Server Management Studio with its results

Applies to SQL Server 2019, 2022 and 2025. The Query Store capture mode decides which queries SQL Server bothers to record. Turning Query Store on is only half the job: the capture mode controls whether every statement gets stored, only the ones that matter, or nothing new at all. I’ve seen it set to ALL…

Read More »

Posted in Performance, Question of the Day, SQL Server

Rebuilding All Indexes on a Table

November 8, 2026
| No Comments
| Performance, Question of the Day, SQL Server
Rebuilding All Indexes on a Table: the T-SQL from this post in SQL Server Management Studio

Applies to SQL Server 2019, 2022 and 2025. When I want to rebuild all indexes on a table in one go, I use ALTER INDEX ALL … REBUILD. It’s one statement instead of one per index, but it does a bit more than people expect, and a bit less on a heap. How to rebuild…

Read More »

Posted in Performance, Question of the Day, SQL Server

Disabled Indexes in SQL Server

November 3, 2026
| No Comments
| Performance, Question of the Day, SQL Server
Disabled Indexes in SQL Server: the T-SQL from this post in SQL Server Management Studio

Applies to SQL Server 2019, 2022 and 2025. SQL Server disabled indexes are handy and a bit dangerous. ALTER INDEX … DISABLE keeps the index definition but throws away its data, and what that means depends entirely on whether the index is nonclustered or clustered. I use it most before big loads and when I…

Read More »

Posted in Performance, Question of the Day, SQL Server

Statistics Problem or Caching Problem?

October 18, 2026
| 3 Comments
| Performance
SQL Server Performance: Statistics Problem or Caching Problem?

When a query that was fine yesterday is slow today, it is nearly always a statistics problem or a caching problem: either the statistics no longer describe the data, or a cached plan built for one parameter value is being reused for another. They need different fixes, so find out which it is first. Tested…

Read More »

Posted in Performance 3 Comments

Plan Caching and Parameterization

October 18, 2026
| 1 Comment
| Performance
SQL Server Performance: Plan Caching and Parameterization

Plan caching is how SQL Server avoids compiling the same statement twice: it compiles a plan the first time it sees a statement and keeps it in the plan cache to reuse. Whether a statement can reuse a plan depends on how it is sent. Too little reuse wastes CPU and memory on compilations; reuse…

Read More »

Posted in Performance 1 Comment

Reading Execution Plans

October 18, 2026
| 3 Comments
| Performance
SQL Server Performance: Reading Execution Plans

Reading execution plans is the quickest way to see how SQL Server decided to run a query. Reading one well comes down to a handful of checks: where the estimates go wrong, where most rows flow, and what the warnings say. Tested on SQL Server 2022 (Developer edition, single test instance). Getting the plan Estimated…

Read More »

Posted in Performance 3 Comments

Measuring Query Performance and Taking a Baseline

October 17, 2026
| 3 Comments
| Performance
SQL Server Performance: Measuring Query Performance and Taking a Baseline

Measuring query performance comes before any tuning, because tuning without measuring is guessing. Before changing a query, an index or a setting, record how the query performs now, make one change, and measure again in the same way. This post covers where the numbers come from. Tested on SQL Server 2022 (Developer edition, single test…

Read More »

Posted in Performance 3 Comments

What Happens During a Data Change: Buffer Pool, Write-Ahead Log and Durability

October 17, 2026
| No Comments
| Performance
SQL Server Performance: What Happens During a Data Change: Buffer Pool, Write-Ahead Log and Durability

Tested on SQL Server 2022 (Developer edition, single test instance). Knowing what SQL Server does with an INSERT, UPDATE or DELETE explains most of the advice about log files, checkpoints, recovery time and why COMMIT can be slow. The steps for a single UPDATE \1. The query processor finds the rows to change, using an…

Read More »

Posted in Performance

Resource Governor

October 17, 2026
| No Comments
| Performance
SQL Server Performance: Resource Governor

Resource Governor (Enterprise edition) puts incoming sessions into workload groups and limits the CPU, memory and I/O each group can use. The typical use is stopping reporting or ad hoc queries from starving the main application. Tested on SQL Server 2022 (Developer edition, single test instance). When to use Resource Governor Resource Governor is worth…

Read More »

Posted in Performance

Table Partitioning

October 16, 2026
| No Comments
| Performance
SQL Server Performance: Table Partitioning

Table partitioning splits one table into separate partitions by the value of one column, usually a date. Its real benefits are management ones: removing a month of old data in seconds, rebuilding one partition instead of the whole table, and placing old data on cheaper storage. It is not a performance fix by itself, and…

Read More »

Posted in Performance

Parameter Sniffing

October 16, 2026
| 2 Comments
| Performance
SQL Server Performance: Parameter Sniffing

Tested on SQL Server 2022 (Developer edition, single test instance). When a stored procedure or parameterised query is first compiled, SQL Server builds the plan for the parameter values used on that first call and reuses it afterwards. If those values were unusual (a customer with ten rows instead of ten million, or the other…

Read More »

Posted in Performance 2 Comments

Performance 01: top queries

October 15, 2026
| No Comments
| Performance
SQL Server Performance: Performance 01: top queries

The queries using the most CPU, reads and time since their plans were cached. Change the ORDER BY to sort by reads or duration. For history across restarts use Query Store (Performance 02). Read-only, changes nothing. Tested on SQL Server 2017 and 2025. — 01_Top_Queries.sql – the queries using the most CPU, reads and time…

Read More »

Posted in Performance

Performance 02: Query Store regressions

October 15, 2026
| 1 Comment
| Performance
SQL Server Performance: Performance 02: Query Store regressions

Run it in the database: queries that got slower in the last 24 hours than in the 7 days before, usually because the plan changed. Needs Query Store turned on. Read-only, changes nothing. Tested on SQL Server 2017 and 2025. — 02_Query_Store_Regressions.sql – run IN the database: queries that got slower in the last 24…

Read More »

Posted in Performance 1 Comment

Performance 03: missing indexes

October 15, 2026
| No Comments
| Performance
SQL Server Performance: Performance 03: missing indexes

Indexes SQL Server thinks would help, across all databases, since start-up, with a CREATE INDEX statement for each. Treat them as hints: check for overlap with existing indexes before creating any. Read-only, changes nothing. Tested on SQL Server 2017 and 2025. — 03_Missing_Indexes.sql – indexes SQL Server thinks would help, across all databases, since start-up….

Read More »

Posted in Performance

Performance 04: unused indexes

October 15, 2026
| No Comments
| Performance
SQL Server Performance: Performance 04: unused indexes

Run it in the database: indexes that are written to but never read since start-up. Only meaningful once the server has been up through a full business cycle (month end and so on). Read-only, changes nothing. Tested on SQL Server 2017 and 2025. — 04_Unused_Indexes.sql – run IN the database: indexes that are written to…

Read More »

Posted in Performance

Performance 05: statistics age

October 15, 2026
| No Comments
| Performance
SQL Server Performance: Performance 05: statistics age

Run it in the database: statistics that are more than 7 days old or have had more than 20% of rows changed since they were last updated. Read-only, changes nothing. Tested on SQL Server 2017 and 2025. — 05_Statistics_Age.sql – run IN the database: statistics that are old or have had many changes since they…

Read More »

Posted in Performance

Performance 06: index fragmentation

October 15, 2026
| No Comments
| Performance
SQL Server Performance: Performance 06: index fragmentation

Run it in the database: fragmentation of every index over 1000 pages, using the light LIMITED scan. Read-only, changes nothing. Tested on SQL Server 2017 and 2025. — 06_Index_Fragmentation.sql – run IN the database: fragmentation of indexes over 1000 pages (LIMITED scan, fairly light). Read-only. SET NOCOUNT ON; SELECT OBJECT_SCHEMA_NAME(ps.object_id) + N’.’ + OBJECT_NAME(ps.object_id) AS…

Read More »

Posted in Performance

Performance 07: cardinality estimate skew

October 15, 2026
| No Comments
| Performance
SQL Server Performance: Performance 07: cardinality estimate skew

Finds where the optimiser’s row estimates are badly wrong, the root of most bad plans. Part 1 works on every version; part 2 (SQL Server 2019 and later) goes operator by operator through the last actual plan and shows the table, index and columns where a filtered statistic would help. Read-only, changes nothing. Tested on…

Read More »

Posted in Performance

Performance 08: filtered statistics candidates

October 15, 2026
| No Comments
| Performance
SQL Server Performance: Performance 08: filtered statistics candidates

Run it in the database: columns whose data is lopsided enough that the normal statistics histogram misleads the optimiser, with the CREATE STATISTICS … WHERE statement that would fix it. It only suggests; it creates nothing. Read-only, changes nothing. Tested on SQL Server 2017 and 2025. /* 08_Filtered_Statistics_Candidates.sql – run IN the database: columns whose…

Read More »

Posted in Performance

Performance 09: duplicate and overlapping indexes

October 15, 2026
| 1 Comment
| Performance
SQL Server Performance: Performance 09: duplicate and overlapping indexes

Run it in the database: indexes that duplicate or are covered by another index, and what they cost in writes. It suggests DROP statements but runs none. Read-only, changes nothing. Tested on SQL Server 2017 and 2025. /* 09_Duplicate_and_Overlapping_Indexes.sql – run IN the database: indexes that duplicate or are covered by another index, and what…

Read More »

Posted in Performance 1 Comment

Performance 10: statistics health

October 15, 2026
| No Comments
| Performance
SQL Server Performance: Performance 10: statistics health

Run it in the database: the auto-statistics settings, how fresh and how well sampled every statistic is, and filtered statistics that have fallen behind. A fuller version of Performance 05. Read-only, changes nothing. Tested on SQL Server 2017 and 2025. /* 10_Statistics_Health.sql – run IN the database: how fresh and how good every statistic is,…

Read More »

Posted in Performance

Performance 11: cardinality estimator audit

October 15, 2026
| No Comments
| Performance
SQL Server Performance: Performance 11: cardinality estimator audit

Which cardinality estimator each database actually uses and why: compatibility level, LEGACY_CARDINALITY_ESTIMATION, trace flags and query hints, with advice on what to change. Read-only, changes nothing. Tested on SQL Server 2017 and 2025. /* 11_CE_Configuration_Audit.sql – which cardinality estimator (CE) each database uses, and why. Clive Roberts DBA, 10 October 2026. Read-only. Server-wide. SQL Server…

Read More »

Posted in Performance

Performance 12: implicit conversions

October 15, 2026
| No Comments
| Performance
SQL Server Performance: Performance 12: implicit conversions

Queries in the plan cache where SQL Server has to convert a column’s data type (usually varchar against nvarchar), which can turn a seek into a scan and ruin row estimates. Read-only, changes nothing. Tested on SQL Server 2017 and 2025. /* 12_Implicit_Conversions.sql – queries in the plan cache where SQL Server has to convert…

Read More »

Posted in Performance

When the SQL Server Cache Needs to Be Cleared

October 11, 2026
| No Comments
| Performance
SQL Server Performance: When the SQL Server Cache Needs to Be Cleared

To check if the SQL Server cache needs to be cleared, you can monitor the performance and memory usage of your SQL Server instance. These checks will tell you whether clearing it would help: Check Memory Usage: SELECT total_physical_memory_kb / 1024 AS TotalMemoryMB, available_physical_memory_kb / 1024 AS AvailableMemoryMB, system_memory_state_desc AS MemoryState FROM sys.dm_os_sys_memory; Monitor Plan…

Read More »

Posted in Performance

Stress Testing the I/O Subsystem with SQLIO

October 11, 2026
| No Comments
| Performance
SQL Server Performance: Stress Testing the I/O Subsystem with SQLIO

Summary Note: Microsoft has retired SQLIO. Use DiskSpd (https://github.com/microsoft/diskspd) for new testing. The principles in this post still apply. The purpose of this document is to provide guidance on using SQLIO.exe to determine the Input/Output capacity of a disk subsystem. This document is focused on how to test configurations for Storage Area Network (SAN) environments…

Read More »

Posted in Performance

Average Write Performance

October 11, 2026
| No Comments
| Performance
SQL Server Performance: Average Write Performance

The average write performance in SQL Server can be measured using the Average Disk sec/Write metric. This metric indicates the average time, in seconds, that it takes to write data to the disk. Points to bear in mind: Performance Counters: SQL Server uses performance counters like Avg. Disk sec/Write to measure I/O latency. Ideally, this…

Read More »

Posted in Performance

Common Memory Issues

October 11, 2026
| No Comments
| Performance
SQL Server Performance: Common Memory Issues

The memory problems I see most often: Memory Pressure: External Memory Pressure: High memory usage by other applications on the server can force SQL Server to reduce its memory usage Internal Memory Pressure: SQL Server components, such as the buffer pool or query execution, can consume excessive memory, leading to performance degradation Insufficient Memory for…

Read More »

Posted in Performance

NUMA

October 10, 2026
| No Comments
| Performance
SQL Server Performance: NUMA

NUMA stands for Non-Uniform Memory Access. It is a computer memory design used in multiprocessing systems, where the memory access time depends on the memory location relative to the processor. Under NUMA, a processor can access its own local memory faster than non-local memory (memory local to another processor or memory shared between processors) This…

Read More »

Posted in Performance

Forwarded Records

October 10, 2026
| No Comments
| Performance
SQL Server Performance: Forwarded Records

Forwarded records: a concept specific to SQL Server’s heap tables. These can have a big impact on performance, especially for update-heavy workloads. What Are Forwarded Records? In SQL Server, a forwarded record occurs when: A row in a heap table (a table without a clustered index) is updated. The new row no longer fits in…

Read More »

Posted in Performance

Data Compression

October 10, 2026
| No Comments
| Performance
SQL Server Performance: Data Compression

SQL Server’s DATA_COMPRESSION feature is a powerful way to reduce storage space and improve I/O performance. Types of DATA_COMPRESSION in SQL Server Compression Type Description Best Use Cases NONE No compression applied. Default setting. ROW Compresses fixed-length data types by storing them more efficiently. Good for OLTP workloads with frequent inserts/updates. PAGE Includes ROW compression…

Read More »

Posted in Performance

Database Performance Tuning and Index Strategy

October 10, 2026
| No Comments
| Performance
SQL Server Performance: Database Performance Tuning and Index Strategy

Optimising a SQL Server database for performance involves a combination of design best practices, query tuning, index management, and system-level configurations. Here’s a structured approach to help you get started: 1. Database Design Optimisation Normalise to reduce redundancy, but de-normalise selectively for performance. Use appropriate data types: avoid over-allocating space (e.g., use INT instead of…

Read More »

Posted in Performance

Find Which Queries Are Using TempDB Right Now

July 29, 2016
| No Comments
| Performance, SQL Server
SQL Server Performance: Find Which Queries Are Using TempDB Right Now

SELECT st.dbid AS QueryExecutionContextDBID, DB_NAME(st.dbid) AS QueryExecContextDBNAME, st.objectid AS ModuleObjectId, SUBSTRING(st.TEXT, dmv_er.statement_start_offset/2 + 1, (CASE WHEN dmv_er.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX),st.TEXT)) * 2 ELSE dmv_er.statement_end_offset END – dmv_er.statement_start_offset)/2) AS Query_Text, dmv_tsu.session_id , dmv_tsu.request_id, dmv_tsu.exec_context_id, (dmv_tsu.user_objects_alloc_page_count – dmv_tsu.user_objects_dealloc_page_count) AS OutStanding_user_objects_page_counts, (dmv_tsu.internal_objects_alloc_page_count – dmv_tsu.internal_objects_dealloc_page_count) AS OutStanding_internal_objects_page_counts, dmv_er.start_time, dmv_er.command, dmv_er.open_transaction_count, dmv_er.percent_complete, dmv_er.estimated_completion_time, dmv_er.cpu_time, dmv_er.total_elapsed_time, dmv_er.reads,dmv_er.writes, dmv_er.logical_reads, dmv_er.granted_query_memory, dmv_es.HOST_NAME,…

Read More »

Posted in Performance, SQL Server

Check VLF Counts for Every SQL Server Database

April 19, 2016
| No Comments
| Performance, SQL Server
SQL Server Performance: Check VLF Counts for Every SQL Server Database

VLF (virtual log file) count per database using sys.dm_db_log_info, which replaces DBCC LOGINFO from SQL Server 2016 SP2. No temp tables or sp_MSforeachdb needed. — High VLF counts can affect write performance — and they can make full database restores and crash recovery take much longer. — Try to keep VLF counts under 200 in…

Read More »

Posted in Performance, SQL Server

SQL Server VLF Details: Count, Size and Log Reuse Wait

March 19, 2016
| No Comments
| Performance, SQL Server
SQL Server Performance: SQL Server VLF Details: Count, Size and Log Reuse Wait

VLF detail per database: count, active VLFs, log size, average VLF size and what is stopping log reuse. Uses sys.dm_db_log_info (SQL Server 2016 SP2 and later). The fix for a high count is at the bottom. — VLF detail per database (SQL Server 2016 SP2 and later) — Shows how many VLFs there are, how…

Read More »

Posted in Performance, SQL Server

Fill Factor

November 11, 2015
| No Comments
| Performance, SQL Server
SQL Server Performance: Fill Factor

Static Tables – Set Fill Factor at 100 (or default server fill factor), As these tables are never changing, keeping the Fill Factor at 100 is the best option. They conserve the space, and also there is no fragmentation. Tables Updated Less Often – Set Fill Factor at 95. These tables are more or less…

Read More »

Posted in Performance, SQL Server

Find Missing Indexes in SQL Server (Top 25 by Impact)

October 26, 2015
| No Comments
| Performance, SQL Server
SQL Server Performance: Find Missing Indexes in SQL Server (Top 25 by Impact)

— 25 missing indexes that will improve performance the most SELECT TOP 25 dm_mid.database_id AS DatabaseID, DB_NAME(dm_mid.database_id) AS [Database], dm_migs.avg_user_impact * ( dm_migs.user_seeks + dm_migs.user_scans ) AS [Avg Estimated Impact], dm_migs.last_user_seek AS [Last Usage Time], OBJECT_NAME(dm_mid.OBJECT_ID, dm_mid.database_id) AS [Table], ‘CREATE INDEX [IDX_’ + OBJECT_NAME(dm_mid.OBJECT_ID, dm_mid.database_id) + ‘_’ + REPLACE(REPLACE(REPLACE(ISNULL(dm_mid.equality_columns, ”), ‘, ‘, ‘_’), ‘[‘, ”),…

Read More »

Posted in Performance, SQL Server

Count CPU Cores and Sockets on a SQL Server

September 18, 2015
| No Comments
| Performance, SQL Server
SQL Server Performance: Count CPU Cores and Sockets on a SQL Server

SELECT( cpu_count / hyperthread_ratio ) AS NumberOfPhysicalCPUs, CASE WHEN hyperthread_ratio = cpu_count THEN cpu_count ELSE(( cpu_count – hyperthread_ratio ) / ( cpu_count / hyperthread_ratio )) END AS NumberOfCoresInEachCPU, CASE WHEN hyperthread_ratio = cpu_count THEN cpu_count ELSE( cpu_count / hyperthread_ratio ) * (( cpu_count – hyperthread_ratio ) / ( cpu_count / hyperthread_ratio )) END AS TotalNumberOfCores,…

Read More »

Posted in Performance, SQL Server

Find Unused Indexes in SQL Server (with DROP Statements)

July 1, 2015
| No Comments
| Performance, SQL Server
SQL Server Performance: Find Unused Indexes in SQL Server (with DROP Statements)

— Unused Index Script SELECT TOP 25 o.name AS ObjectName , i.name AS IndexName , i.index_id AS IndexID , dm_ius.user_seeks AS UserSeek , dm_ius.user_scans AS UserScans , dm_ius.user_lookups AS UserLookups , dm_ius.user_updates AS UserUpdates , p.TableRows , ‘DROP INDEX ‘ + QUOTENAME(i.name) + ‘ ON ‘ + QUOTENAME(s.name) + ‘.’ + QUOTENAME(OBJECT_NAME(dm_ius.OBJECT_ID)) AS ‘drop statement’…

Read More »

Posted in Performance, SQL Server

Show Wait Types for SQL Server System Tasks

July 1, 2015
| No Comments
| Performance, SQL Server
SQL Server Performance: Show Wait Types for SQL Server System Tasks

SELECT DISTINCT wt.wait_type FROM sys.dm_os_waiting_tasks AS wt JOIN sys.dm_exec_sessions AS s ON wt.session_id = s.session_id WHERE s.is_user_process = 0

Read More »

Posted in Performance, SQL Server

Key SQL Server Performance Counters with T-SQL

July 1, 2015
| 1 Comment
| Performance, SQL Server
SQL Server Performance: Key SQL Server Performance Counters with T-SQL

DECLARE @CounterPrefix NVARCHAR(30) SET @CounterPrefix = CASE WHEN @@SERVICENAME = ‘MSSQLSERVER’ THEN ‘SQLServer:’ ELSE ‘MSSQL$’ + @@SERVICENAME + ‘:’ END ; — Capture the first counter set SELECT CAST(1 AS INT) AS collection_instance , [OBJECT_NAME] , counter_name , instance_name , cntr_value , cntr_type , CURRENT_TIMESTAMP AS collection_time INTO #perf_counters_init FROM sys.dm_os_performance_counters WHERE ( OBJECT_NAME =…

Read More »

Posted in Performance, SQL Server 1 Comment

Top 10 SQL Server Queries by Physical Reads

July 1, 2015
| No Comments
| Performance, SQL Server
SQL Server Performance: Top 10 SQL Server Queries by Physical Reads

SELECT TOP 10 execution_count , statement_start_offset AS stmt_start_offset , sql_handle , plan_handle , total_logical_reads / execution_count AS avg_logical_reads , total_logical_writes / execution_count AS avg_logical_writes , total_physical_reads / execution_count AS avg_physical_reads , t.text FROM sys.dm_exec_query_stats AS s CROSS APPLY sys.dm_exec_sql_text(s.sql_handle) AS t ORDER BY avg_physical_reads DESC

Read More »

Posted in Performance, SQL Server

Top 10 SQL Server Wait Types (sys.dm_os_wait_stats)

July 1, 2015
| No Comments
| Performance, SQL Server
SQL Server Performance: Top 10 SQL Server Wait Types (sys.dm_os_wait_stats)

SELECT TOP 10 wait_type , max_wait_time_ms wait_time_ms , signal_wait_time_ms , wait_time_ms – signal_wait_time_ms AS resource_wait_time_ms , 100.0 * wait_time_ms / SUM(wait_time_ms) OVER ( ) AS percent_total_waits , 100.0 * signal_wait_time_ms / SUM(signal_wait_time_ms) OVER ( ) AS percent_total_signal_waits , 100.0 * ( wait_time_ms – signal_wait_time_ms ) / SUM(wait_time_ms) OVER ( ) AS percent_total_resource_waits FROM sys.dm_os_wait_stats WHERE…

Read More »

Posted in Performance, SQL Server

Index type

May 19, 2015
| No Comments
| Performance, SQL Server
SQL Server Performance: Index type

Index type Description Clustered A clustered index sorts and stores the data rows of the table or view in order based on the clustered index key. The clustered index is implemented as a B-tree index structure that supports fast retrieval of the rows, based on their clustered index key values. Non clustered A non clustered…

Read More »

Posted in Performance, SQL Server

Find Tables Without a Clustered Index (Heaps) in SQL Server

April 15, 2015
| No Comments
| Performance, SQL Server
SQL Server Performance: Find Tables Without a Clustered Index (Heaps) in SQL Server

To analyze further, the following query can be used to find out which indexes don’t have clustered indexes defined: WITH CTE_1 AS ( SELECT db_name() as dbname, o.name as tablename, (SELECT SUM(p.rows) FROM sys.partitions p WHERE p.index_id = i.index_id AND i.object_id = p.object_id) as number_of_rows FROM sys.indexes i INNER JOIN sys.objects o ON i.object_id =…

Read More »

Posted in Performance, SQL Server

Measure SQL Server Transactions per Second with a DMV

December 4, 2014
| No Comments
| Performance, SQL Server
SQL Server Performance: Measure SQL Server Transactions per Second with a DMV

As we use PERFMON – Performance Monitor to identify real time happening on SQL Server, Here using a DMV “sys.dm_os_performance_counters” may be used to calculate number of transactions on SQL Server as DECLARE @Counter bigint SELECT @Counter = cntr_value FROM sys.dm_os_performance_counters WHERE counter_name = ‘Transactions/sec’ AND object_name = ‘SQLServer:Databases’ AND instance_name = ‘Test’ — Your…

Read More »

Posted in Performance, SQL Server

List Tables With No Primary Key in SQL Server

March 10, 2014
| No Comments
| Performance, SQL Server
SQL Server Performance: List Tables With No Primary Key in SQL Server

SELECT DB_NAME() AS [Database], T.TABLE_NAME AS [Tables without Primary Keys] FROM INFORMATION_SCHEMA.TABLES AS T WHERE NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS TC WHERE CONSTRAINT_TYPE = ‘PRIMARY KEY’ AND T.TABLE_NAME = TC.TABLE_NAME) AND T.TABLE_TYPE = ‘BASE TABLE’

Read More »

Posted in Performance, SQL Server

SQL Server DBA Handbook

Setup, backup and high availability (37)
  • Backing Up and Restoring a Database
  • Restoring a Full Database Backup (SSMS)
  • Restoring a Database to a New Location
  • Backup and Restore with T-SQL
  • Disaster Recovery Planning
  • Basic vs Advanced High Availability
  • Adding a Database to an Availability Group
  • Suspending and Resuming Data Movement
  • Availability Group Health Troubleshooting
  • Quorum Failure
  • Log Shipping
  • Database Mail Setup and Troubleshooting
  • Moving TempDB
  • Database Snapshots
  • Server Build Checklist
  • Encryption
  • TDE: Backing Up the Certificate
  • Data Obfuscation and Masking
  • SQL Server Audit
  • FILESTREAM
  • Orphaned SQL Logins
  • Replicating SQL Server Logins with Their SIDs
  • Login Failures (Error 18456)
  • Random Password Generator
  • Generating the SPNs (Kerberos)
  • SQL Server Replication: Setup, Types and Pitfalls
  • Adding an Article to a Publication
  • Enabling Change Tracking: Good and Bad Points
  • Migrating a Reporting Services Installation (Native Mode)
  • Upgrading SSRS 2005 to 2012 (Quick and Dirty)
  • Azure SQL Options
  • Migrating SQL Server to Azure
  • Building an Availability Group
  • Failover Cluster Instances and Distributed Availability Groups
  • Backup to URL and Backup Encryption
  • PowerShell and dbatools
  • SQL Server Trace Flags
Performance (16)
  • Database Performance Tuning and Index Strategy
  • Data Compression
  • Forwarded Records
  • NUMA
  • Common Memory Issues
  • Average Write Performance
  • Stress Testing the I/O Subsystem with SQLIO
  • When the SQL Server Cache Needs to Be Cleared
  • Parameter Sniffing
  • Table Partitioning
  • Resource Governor
  • What Happens During a Data Change: Buffer Pool, Write-Ahead Log and Durability
  • Measuring Query Performance and Taking a Baseline
  • Reading Execution Plans
  • Plan Caching and Parameterization
  • Statistics Problem or Caching Problem?
Troubleshooting (21)
  • Database Suspect, Recovery Pending or Stuck Recovering
  • Shrinking Databases
  • Transaction Log Full
  • Data File Full and Disk Space (Error 1105)
  • Shrinking Transaction Logs
  • Stopping a Running Job in Job Activity Monitor
  • Failed SQL Agent Job Triage
  • Single-User Mode
  • Tempdb Full or Contention
  • Repairing the WMI Provider (mofcomp)
  • SQL Server Referencing the Wrong Disk Drives
  • Performance Troubleshooting Queries
  • High CPU Troubleshooting
  • SQL Locks
  • SQL Server Error Numbers
  • Monitoring Deadlocks
  • Sleeping Processes
  • DMVs and Session Monitoring
  • Collecting Data with Performance Monitor
  • Collecting a Trace with SQL Profiler
  • Schema Locks and Online Index Maintenance
T-SQL (17)
  • SQL Best Practices
  • T-SQL Coding Conventions and Programming Guidelines
  • Common Table Expressions (CTEs)
  • CROSS APPLY and OUTER APPLY
  • Exporting Data to a File
  • SET IDENTITY_INSERT
  • OPENQUERY with Linked Servers
  • Service Broker in SQL Server
  • Enabling and Resetting Service Broker
  • Change Data Capture (CDC)
  • Extended Events
  • Temporal Tables
  • DDL and DML Audit Triggers
  • Transaction Modes: Autocommit, Explicit and Implicit
  • Error Handling in Transactions: TRY/CATCH, @@TRANCOUNT and XACT_STATE()
  • Read Consistency: Read Committed, RCSI and Snapshot Isolation
  • T-SQL Performance Anti-Patterns

Question of the Day

Setup, backup and high availability (5)
  • Encrypting SQL Server Connections
  • SQL Server Certificate Expiry
  • Moving the SQL Server Error Log
  • Backing Up the Database Master Key
  • Fixed Server Roles in SQL Server
Performance (3)
  • Query Store Capture Mode
  • Rebuilding All Indexes on a Table
  • Disabled Indexes in SQL Server
Troubleshooting (3)
  • Running Scripts with the sqlcmd Utility
  • SQL Server Audit Failures
  • Starting SQL Server with Minimal Configuration
T-SQL (24)
  • Converting Money in T-SQL
  • RANK, DENSE_RANK and ROW_NUMBER
  • Finding Special Characters with PATINDEX
  • COUNT(*) vs COUNT(1) in SQL Server
  • The T-SQL FORMAT Function
  • The Table Value Constructor in SQL Server
  • CREATE PROCEDURE in SQL Server
  • The T-SQL AVG Function
  • @@SERVICENAME and the SQL Server Service Name
  • The SQL Server bit Data Type
  • ALTER SCHEMA TRANSFER
  • The BIT_COUNT Function
  • The STRING_ESCAPE Function
  • The T-SQL BETWEEN Operator
  • The T-SQL SQUARE Function
  • Using a Column Alias in ORDER BY
  • The T-SQL SIGN Function
  • T-SQL Reserved Keywords
  • Adding a Column with a DEFAULT
  • Trailing Spaces in SQL Server
  • SQL Server Regex Functions
  • Aggregates on Empty Sets in T-SQL
  • The SQL Server Vector Data Type
  • The T-SQL CHOOSE Function

All Question of the Day posts (35)

Categories

Sidebar

  • Handbook, news and patches (121)
  • Regain sysadmin access (1)
  • Kill SQL processes (1)
  • Configure MSDB (13)
  • TempDB in use (1)
  • Connected to SQL (1)
  • Move backups (2)
  • VLF details (1)
  • Config Manager error (1)
  • Fill factor (1)
  • Missing indexes (1)
  • Number of cores (1)
  • DBCC CHECKDB (1)
  • Wait times (7)
  • Tail-log backup (1)
  • STUFF function (6)
  • Blocking and deadlocks (2)
  • Locking hints (2)
  • Errors 823, 824, 825 (1)
  • DBCC commands (1)
  • Transaction counts (1)
  • Database details (1)
  • Replication (1)
  • Find jobs (1)
  • Backup progress (1)
  • Pivot table (1)
  • Replication objects (1)
  • Tables with no PK (1)
  • Who dropped the database (1)
  • last_value (1)
  • Parse XML (1)
  • Search a string (1)
  • DATETIME difference (1)
  • Error 3707 (1)
  • SHRINKDATABASE (1)
  • Express backup (1)
  • Enable xp_cmdshell (1)
  • Output a file (1)
  • Start of the month (1)

RSS feed: Clive Roberts Clive Roberts

  • RANK, DENSE_RANK and ROW_NUMBER
    Applies to SQL Server 2019, 2022 and 2025. RANK vs DENSE_RANK is one of those choices that looks cosmetic until a report goes out with the wrong number of rows on it. Both number rows in order and both give tied rows the same number. The difference is what happens to the number after a... […]

Recent Posts

  • Converting Money in T-SQL
  • Maintenance Scripts: Ola Hallengren’s Maintenance Solution 20261129_113033
  • RANK, DENSE_RANK and ROW_NUMBER
  • News: [Video] Office Hours: Reflecting on Microsoft Ignite from Cabo
  • Encrypting SQL Server Connections
  • News: Microsoft’s AI Skills Repo Has a Lot of Potential.
  • Running Scripts with the sqlcmd Utility
  • News: What to Do When the SQL Server Keeps Crashing
  • Finding Special Characters with PATINDEX
  • SQL Server Installs Tested Before and After with dbatools and Pester
  • COUNT(*) vs COUNT(1) in SQL Server
  • The T-SQL FORMAT Function
  • News: SQL Server 2022 SQLskills Blackbelt Credly badge now available
  • The Table Value Constructor in SQL Server
  • CREATE PROCEDURE in SQL Server
  • News: [Video] Office Hours: Back from the PASS Summit
  • The T-SQL AVG Function
  • News: Black Friday Sale – Blackbelt for $399!
  • Capacity Report: When Each Drive Will Be Full
  • SQL Server Security Report: Who Has sysadmin, and What Changed
  • SQL Server Patch Report: Every Instance Against Its Target Build
  • Windows Patch Report: Did This Month’s Updates Land?
  • Integrity Check Report: Proving CHECKDB Actually Ran
  • News: Modernize your apps with Azure SQL Database Hyperscale
  • News: Would Open-Sourcing Microsoft SQL Server Actually Fix Anything?
  • SQL Server Certificate Expiry
  • News: Make Your Nightly ETL Faster with TABLOCKX
  • @@SERVICENAME and the SQL Server Service Name
  • Moving the SQL Server Error Log
  • News: FGCB_ADD_REMOVE Latch Investigation Demo
  • Who Is Really a Sysadmin? Expanding AD Groups in SQL Server with xp_logininfo
  • SSIS Error Report: Finding the Package That Failed
  • Backup Report: Is Every Database Backed Up?
  • Database Inventory Report
  • SQL Server Inventory Report
  • Disk Space Alerts for SQL Server
  • Server Availability Report: Ping and Response Time
  • SQL Server Licensing Report
  • Query Store Capture Mode
  • SQL Server Audit Failures
  • News: [Video] Office Hours in the Backyard
  • The SQL Server bit Data Type
  • News: What Students are Saying About My Latest Classes
  • ALTER SCHEMA TRANSFER
  • News: How to Set Background Images & Movies in SSMS v22
  • Starting SQL Server with Minimal Configuration
  • News: Are Blogs Still Relevant? #tsql2sday
  • Backing Up the Database Master Key
  • News: Free Webcast: My Favorite Query Hints
  • News: Announcing Microsoft Database Hub: An Incredible Pace of Innovation
  • The BIT_COUNT Function
  • Rebuilding All Indexes on a Table
  • The STRING_ESCAPE Function
  • The T-SQL BETWEEN Operator
  • News: [Video] Office Hours: An AI Agent Stops In to Ask a Question
  • The T-SQL SQUARE Function
  • News: The Top 10 SQL Server Wait Types, Worldwide
  • Using a Column Alias in ORDER BY
  • Disabled Indexes in SQL Server
  • News: Who’s Hiring Database People? November 2026 Edition
  • The T-SQL SIGN Function
  • News: My Black Friday Sale on Training Classes is Open Now!
  • T-SQL Reserved Keywords
  • Patch: SQL Server 2022 CU28 (build 16.0.4325.4)
  • Patch: SQL Server 2025 CU11 (build 17.0.5065.9)
  • Patch: SQL Server 2017 CU31 + GDR (build 14.0.3570.2)
  • Patch: SQL Server 2017 GDR (build 14.0.2150.2)
  • Patch: SQL Server 2019 CU32 + GDR (build 15.0.4510.2)
  • Patch: SQL Server 2019 GDR (build 15.0.2210.4)
  • Patch: SQL Server 2022 CU27 + GDR (build 16.0.4315.2)
  • Patch: SQL Server 2022 GDR (build 16.0.1220.3)
  • Patch: SQL Server 2025 CU10 + GDR (build 17.0.5045.3)
  • Patch: SQL Server 2025 GDR (build 17.0.1155.3)
  • Adding a Column with a DEFAULT
  • News: [Video] Office Hours: 4 Great Questions Off Canada
  • Trailing Spaces in SQL Server
  • News: Meet Hugo Kornelis, Execution Plan Expert.
  • SQL Server Regex Functions
  • News: Why You Don’t Get Parallelism When You Ask for The Whole Table
  • Fixed Server Roles in SQL Server
  • News: New Stuff in the Mastering Server Tuning Class
  • Aggregates on Empty Sets in T-SQL
  • News: This Friday’s the Deadline for My Next Live Class Rotation.
  • The SQL Server Vector Data Type
  • The T-SQL CHOOSE Function
  • News: [Video] Talking Pronouns in Alaska
  • News: Why’s This Query So Slow in Prod? Check sp_BlitzPlanCompare.
  • News: AI Stories and Thoughts
  • News: I’m Probably Not Supposed To Show You Microsoft’s Auto-Indexing Tool.
  • SQL Server Trace Flags
  • Statistics Problem or Caching Problem?
  • Plan Caching and Parameterization
  • T-SQL Performance Anti-Patterns
  • Reading Execution Plans
  • Measuring Query Performance and Taking a Baseline
  • News: Thoughts on AI After My Panel Discussion
  • Read Consistency: Read Committed, RCSI and Snapshot Isolation
  • Schema Locks and Online Index Maintenance
  • What Happens During a Data Change: Buffer Pool, Write-Ahead Log and Durability
  • Error Handling in Transactions: TRY/CATCH, @@TRANCOUNT and XACT_STATE()
  • Transaction Modes: Auto commit, Explicit and Implicit
  • PowerShell and dbatools
  • Resource Governor
  • Table Partitioning
  • Backup to URL and Backup Encryption
  • Failover Cluster Instances and Distributed Availability Groups
  • Building an Availability Group
  • Parameter Sniffing
  • DDL and DML Audit Triggers
  • Temporal Tables
  • Extended Events
  • Change Data Capture (CDC)
  • Migrating SQL Server to Azure
  • Azure SQL Options
  • News: [Video] Office Hours on the Last Alaskan Cruise of the Season
  • Upgrading SSRS 2005 to 2012 (Quick and Dirty)
  • Migrating a Reporting Services Installation (Native Mode)
  • Health Check 00: is this SQL Server running well?
  • Health Check 01: server overview
  • Health Check 02: databases
  • Health Check 03: backups
  • Health Check 04: disks and files
  • Health Check 05: SQL Agent jobs
  • Health Check 06: wait statistics
  • Health Check 07: activity and blocking
  • Health Check 08: error log
  • Health Check 09: integrity checks
  • Health Check 10: memory and CPU
  • Health Check 11: tempdb
  • Health Check 12: high availability
  • Performance 01: top queries
  • Performance 02: Query Store regressions
  • Performance 03: missing indexes
  • Performance 04: unused indexes
  • Performance 05: statistics age
  • Performance 06: index fragmentation
  • Performance 07: cardinality estimate skew
  • Performance 08: filtered statistics candidates
  • Performance 09: duplicate and overlapping indexes
  • Performance 10: statistics health
  • Performance 11: cardinality estimator audit
  • Performance 12: implicit conversions
  • Enabling Change Tracking: Good and Bad Points
  • Adding an Article to a Publication
  • SQL Server Replication: Setup, Types and Pitfalls
  • Enabling and Resetting Service Broker
  • Service Broker in SQL Server
  • OPENQUERY with Linked Servers
  • News: Breaking News: Hold Off on SSMS 22.11.0
  • News: Fact-Checking Microsoft’s “PostgreSQL to SQL Field Notes: Connections”
  • SET IDENTITY_INSERT
  • Exporting Data to a File
  • CROSS APPLY and OUTER APPLY
  • Common Table Expressions (CTEs)
  • T-SQL Coding Conventions and Programming Guidelines
  • SQL Best Practices
  • Generating the SPNs (Kerberos)
  • Random Password Generator
  • News: Free Webcast: How to Think Like the SQL Server & Postgres Engines
  • Login Failures (Error 18456)
  • Replicating SQL Server Logins with Their SIDs
  • Orphaned SQL Logins
  • FILESTREAM
  • SQL Server Audit
  • Patch: SQL Server 2017 CU31 + GDR (build 14.0.3560.2)
  • Patch: SQL Server 2017 GDR (build 14.0.2140.2)
  • Patch: SQL Server 2019 CU32 + GDR (build 15.0.4500.2)
  • Patch: SQL Server 2019 GDR (build 15.0.2200.2)
  • Patch: SQL Server 2022 CU27 + GDR (build 16.0.4305.5)
  • Patch: SQL Server 2022 GDR (build 16.0.1210.3)
  • Patch: SQL Server 2025 CU9 + GDR (build 17.0.5015.4)
  • Patch: SQL Server 2025 GDR (build 17.0.1145.4)
  • Data Obfuscation and Masking
  • TDE: Backing Up the Certificate
  • Encryption
  • Collecting a Trace with SQL Profiler
  • Collecting Data with Performance Monitor
  • DMVs and Session Monitoring
  • Sleeping Processes
  • Monitoring Deadlocks
  • SQL Server Error Numbers
  • SQL Locks
  • High CPU Troubleshooting
  • Performance Troubleshooting Queries
  • When the SQL Server Cache Needs to Be Cleared
  • Stress Testing the I/O Subsystem with SQLIO
  • Average Write Performance
  • Common Memory Issues
  • NUMA
  • Forwarded Records
  • Data Compression
  • Database Performance Tuning and Index Strategy
  • Server Build Checklist
  • SQL Server Referencing the Wrong Disk Drives
  • Repairing the WMI Provider (mofcomp)
  • Database Snapshots
  • Tempdb Full or Contention
  • Moving TempDB
  • Single-User Mode
  • Database Mail Setup and Troubleshooting
  • Setup
  • Performance
  • Health Check
  • Troubleshooting
  • T-SQL
  • Patches
  • News
  • Audit
  • Projects

Precious Lite 2025 | All Rights Reserved. Precious Lite theme by Flythemes