Use when writing or reviewing MSSQL/T-SQL, creating stored procedures, designing table schemas, writing views, building migrations, defining custom types, or architecting a SQL Server application database. Also use when writing RAISERROR patterns, CHECK constraints with scalar functions, base/subtype table hierarchies, composite key designs, role-scoped views with row-level security, or idempotent DDL scripts. If you are touching MSSQL for an application database, use this skill. Not for PostgreSQL, MySQL, Oracle, or SQLite — patterns are SQL Server-specific.
95
94%
Does it follow best practices?
Impact
98%
1.81xAverage score across 5 eval scenarios
Passed
No known issues
A SaaS platform sends transactional emails and SMS messages to users: welcome emails, password resets, billing receipts, and security alerts. Currently these are fired synchronously during web requests, causing latency and lost messages when the email provider is slow. The team wants to move to an asynchronous notification queue backed by SQL Server — keeping the notifications as first-class relational records (so they can be audited, retried, and reported on) while also treating them as work items to be processed by background workers.
The platform has two types of notifications that currently matter: email notifications (which need recipient address, subject, and body) and SMS notifications (which need a phone number and message text). Both types share the same lifecycle tracking: they start pending, get picked up by a worker, succeed or fail, and can be retried up to a configurable number of times before being marked as permanently failed.
Multiple worker processes run in parallel and compete for the same queue. A configuration value for the maximum number of retry attempts should be stored centrally and readable by the worker without hardcoding the value into the procedure.
The team needs:
Produce a SQL script file named queue.sql containing:
All objects should use named custom types where applicable. Assume the custom types (_Timestamp, _Bool, _Int, _Type, etc.) are already defined and available.