// library
Severity
Bucket
Do not perform multiple DB queries inside a loop for data you could fetch in one query. Instead, consolidate using IN clauses or JOINs to retrieve all needed data at once.
Extract reusable SQL fragments/builders for commonly repeated WHERE/ORDER clauses.
Use executemany/bulk operations and commit in sensible batches for large writes.
Use appropriate column types/lengths (e.g., NVARCHAR(128) vs NVARCHAR(MAX)) for fields with known bounds.
Deduplicate identical queries within a request; reuse previously fetched data or preload in a single query.
Set sensible timeouts for queries/transactions and avoid excessively long timeouts that mask problems.
Prefer set-based SQL (DELETE/UPDATE with WHERE IN/JOIN) or chunked batches over per-row statements.
Always specify ORDER BY when the processing logic relies on a particular order.
25–32 of 32