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 law firm is building a case management system on SQL Server. The domain has a natural hierarchy: a Law Firm has many Clients, each Client has many Cases, each Case has many Documents, and each Document can have multiple Revisions. The team needs the table schema and key-generation infrastructure for this hierarchy.
The team has previously struggled with databases where a query like "find all revisions for client X's cases" required joining through four tables using opaque row numbers. They want a design where the relationships are explicit in the data model and support staff can read meaningful identifiers directly from the keys — knowing that they're looking at Client 42's Case 3, Document 7, Revision 2 without having to look anything up.
The system should support these read patterns:
The schema should include all tables in the hierarchy with proper composite primary keys, well-named foreign key constraints, and the scalar functions needed to generate keys for new records at each level.
Produce a SQL script file named schema.sql containing:
The script should be self-contained and runnable on a fresh SQL Server database. Name output files as specified.