-- Split: Get all orders for given list of IDs DECLARE @Ids VARCHAR(MAX) = '101,205,389,476'; SELECT o.* FROM Orders o INNER JOIN STRING_SPLIT(@Ids, ',') AS s ON o.OrderId = CAST(s.value AS INT); -- Aggregate: Build a comma-separated list of product names for a category SELECT CategoryId, STRING_AGG(ProductName, ', ') WITHIN GROUP (ORDER BY ProductName) AS Products FROM Products GROUP BY CategoryId;
-- Trace flag 1222 logs deadlocks to ERRORLOG DBCC TRACEON(1222, -1); Then analyze the graph. The most common fix: ensure all procedures access tables in the . sqlserver developer
-- Old mess: DATEADD(month, DATEDIFF(month, 0, OrderDate), 0) -- New clean: SELECT DATETRUNC(month, OrderDate) AS OrderMonth, SUM(Amount) FROM Orders GROUP BY DATETRUNC(month, OrderDate); -- Time-series bucketing (every 3 days) SELECT DATE_BUCKET(day, 3, OrderDate) AS Bucket, COUNT(*) FROM Orders GROUP BY DATE_BUCKET(day, 3, OrderDate); Nothing ruins a production system faster than deadlocks and long-held locks. 4.1 Isolation Levels – Choose Wisely | Level | Anomaly Prevented | Concurrency Impact | |-------|-------------------|--------------------| | READ UNCOMMITTED (or NOLOCK hint) | None (dirty reads possible) | High (no shared locks) | | READ COMMITTED (default) | Dirty reads | Medium (locks held briefly) | | REPEATABLE READ | Non-repeatable reads | Lower (holds locks until end of transaction) | | SERIALIZABLE | Phantom reads | Very low (range locks) | | READ COMMITTED SNAPSHOT (RCSI) | Dirty reads via row versioning | High (no locks for readers) | -- Split: Get all orders for given list
EXEC dbo.sp_WhoIsActive @get_plans = 1, @get_outer_command = 1; It shows: blocking chains, query text, plan, tempdb usage, and more. Your flight recorder. Force good plans, revert bad ones. @get_outer_command = 1