SQL Anti-Patterns Detection & Remediation
This skill helps identify common SQL Server performance anti-patterns and provides proven fixes.
When to Use
- •Reviewing stored procedures, views, or queries for performance issues
- •Analyzing slow-running SQL code
- •Performing SQL code reviews
- •Rewriting suboptimal T-SQL patterns
Severity Levels
| Level | Impact | Action |
|---|---|---|
| Critical | >10x performance degradation | Fix immediately |
| High | 5-10x performance degradation | Fix before production |
| Medium | 2-5x performance degradation | Fix in next sprint |
| Low | <2x but measurable | Address when convenient |
Anti-Pattern Catalog
Detailed catalog with before/after examples for each anti-pattern:
Quick Reference
Critical Anti-Patterns
- •Non-SARGable predicates — Functions on indexed columns force full table scans
- •Cursor / RBAR processing — Row-by-row instead of set-based operations
- •Cartesian products — Missing or incorrect JOIN predicates
High Anti-Patterns
- •SELECT * — Unnecessary columns, prevents covering index usage
- •Scalar subqueries in SELECT — Execute once per outer row
- •LIKE with leading wildcard — Cannot use B-tree index
- •Implicit type conversion — Mismatched types force column conversion
Medium Anti-Patterns
- •Missing error handling — No TRY/CATCH, partial execution risk
- •Unnecessary DISTINCT — Masks duplicates from bad joins
- •Parameter sniffing — First plan may be suboptimal for later values
Low Anti-Patterns
- •Missing SET NOCOUNT ON — Extra network roundtrips
- •Temp table without cleanup — Resource leak in long sessions