SQL Development
Optimized for current PostgreSQL, MySQL, and SQL Server releases plus migration-first database workflows.
Comprehensive SQL development guidelines combining SQL coding standards, stored procedure generation, and MS SQL Server DBA best practices.
- Leverage native parallel subagent dispatch and 200k+ context windows where available.
Anti-Patterns
- Using
SELECT * in production queries: It hides contract drift and pulls more data than the caller needs.
- Writing non-SARGable predicates: Functions on indexed columns turn otherwise cheap queries into table scans.
- Ignoring transaction and lock behavior: Correct SQL needs both logical correctness and concurrency safety.
Verification Protocol
Before claiming "skill applied successfully":
- Pass/fail: The SQL Development implementation names the target runtime, framework version, and affected files.
- Pass/fail: Build, lint, test, or equivalent local validation is run for the changed surface.
- Pass/fail: Edge cases for errors, dependency drift, and environment differences are addressed or explicitly out of scope.
- Pressure-test scenario: Apply the workflow to a change that passes happy-path tests but fails one boundary condition.
- Success metric: Zero untested success claims; every implementation claim maps to a command or artifact.
Before and After Example
-- Before
SELECT *
FROM Orders
WHERE YEAR(created_at) = 2026;
-- After
SELECT order_id, customer_id, created_at, total_amount
FROM Orders
WHERE created_at >= '2026-01-01'
AND created_at < '2027-01-01';
Uses explicit columns and a SARGable date range so indexes can do their work.
Activation Conditions
Use symptom -> action triggers: when one matches, apply this skill and verify with the protocol below.
- Writing SQL queries and stored procedures
- Designing database schemas and table structures
- Working with MS SQL Server as a DBA
- Performance tuning and query optimization
- Database backup, restore, and security configuration
- SQL Server 2025+ feature adoption and migration
Part 1: Database Schema Design
Table Naming
- All table names in singular form
- All column names in singular form
Required Columns
- All tables must have a primary key column named
id
- All tables must have
created_at for creation timestamp
- All tables must have
updated_at for last update timestamp
Constraints
- All tables must have a primary key constraint
- All foreign key constraints must have a name
- All foreign key constraints defined inline
- All foreign keys must have
ON DELETE CASCADE
- All foreign keys must have
ON UPDATE CASCADE
- All foreign keys must reference the primary key of the parent table
Part 2: SQL Coding Style
Formatting
- Uppercase for SQL keywords (
SELECT, FROM, WHERE)
- Consistent indentation for nested queries
- Comments to explain complex logic
- Break long queries into multiple lines
- Organize clauses:
SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY
Query Structure
- Use explicit column names, never
SELECT *
- Qualify column names with table alias when using multiple tables
- Prefer JOINs over subqueries when possible
- Include
LIMIT/TOP clauses to restrict result sets
- Use appropriate indexing for frequently queried columns
- Avoid functions on indexed columns in
WHERE clauses
Part 3: Stored Procedure Standards
Naming Conventions
- Prefix with
usp_
- Use PascalCase:
usp_GetCustomerOrders
- Include plural noun for multiple records:
usp_GetProducts
- Include singular noun for single record:
usp_GetProduct
Parameter Handling
- Prefix parameters with
@
- Use camelCase:
@customerId
- Provide default values for optional parameters
- Validate parameter values before use
- Document parameters with comments
- Required parameters first, optional later
Structure
- Include header comment block with description, parameters, return values
- Return standardized error codes/messages
- Return result sets with consistent column order
- Use
OUTPUT parameters for returning status information
- Prefix temporary tables with
tmp_
- Include
SET NOCOUNT ON for data-modifying procedures
Part 4: Security Best Practices
Query Security
- Parameterize all queries to prevent SQL injection
- Use prepared statements for dynamic SQL
- Avoid embedding credentials in SQL scripts
- Proper error handling without exposing system details
- Avoid dynamic SQL in stored procedures
Transaction Management
- Explicitly begin and commit transactions
- Use appropriate isolation levels
- Avoid long-running transactions that lock tables
- Use batch processing for large data operations
Part 5: MS SQL Server DBA
Tooling
- Install and enable
ms-mssql.mssql VS Code extension for full database management
- Use official Microsoft documentation for reference and troubleshooting
DBA Responsibilities
- Database creation and configuration
- Backup and restore strategies
- Performance tuning and index optimization
- Security management and auditing
- Upgrades and compatibility planning (SQL Server 2025+)
Best Practices
- Focus on tool-based database inspection over codebase analysis
- Highlight deprecated/discontinued features in SQL Server 2025+
- Encourage secure, auditable, performance-oriented solutions
- Reference official docs for troubleshooting
- Warn about deprecated features and suggest alternatives
Troubleshooting
| Issue |
Solution |
| Slow queries |
Check execution plan, add indexes, optimize JOINs |
| Deadlocks |
Reduce transaction scope, consistent lock ordering |
| Missing data |
Verify CASCADE rules, check transaction isolation |
| Permission errors |
Review GRANT/REVOKE statements, check role membership |
| Connection issues |
Verify firewall rules, connection strings, SQL auth settings |
Common Pitfalls
- Using
SELECT * in production queries: It hides contract drift and pulls more data than the caller actually needs.
- Writing non-SARGable predicates: Functions on indexed columns turn otherwise cheap queries into table scans.
- Skipping transaction and lock analysis: Correct SQL needs both logical correctness and concurrency safety.
References & Resources
Documentation
- T-SQL Patterns — MERGE, CTEs, PIVOT, JSON operations, window functions, and error handling
- Performance Tuning — Execution plans, index tuning, Query Store, and anti-patterns
Scripts
Examples
Cross-Client Portability
This skill is written to stay usable across GitHub Copilot, Claude Code, and Codex.
- GitHub Copilot: keep the folder in a Copilot-visible skill path or wrap the
workflow in project instructions when folder discovery is unavailable.
- Claude Code: keep the folder in a local skills directory or a compatible plugin source.
- Codex: install or sync the folder into
$CODEX_HOME/skills/sql-development and restart Codex after major changes.
MCP Availability And Fallback
Preferred MCP Server: None required
- Fallback prompt: "Use the SQL Development skill without MCP. Rely on the local
SKILL.md, bundled references or scripts, and manual verification. Show the exact commands, evidence, and final checks you used before concluding."
- If the current host does not expose a matching server, use the bundled references, scripts, native toolchain, and manual workflow already described in this skill.
- Treat direct local verification, rendered output, logs, tests, or screenshots as the fallback evidence path before completion.
Related Skills
- php-development: Use it when the workflow also needs modern PHP backend implementation.
- powerbi-modeling: Use it when the workflow also needs Power BI semantic model design and DAX work.
- code-quality: Use it when the workflow also needs two-stage review (spec compliance first, then code quality), maintainability, and refactoring guidance.
- systematic-debugging: Use it when the workflow also needs root-cause debugging before proposing fixes.
1---2name: sql-development3description: T-SQL, stored procedures, and MS SQL Server DBA practices. Use when writing SQL queries, designing schemas, tuning SQL Server performance, managing backups, configuring security, or using SQL Server 2025+ features.4---5# SQL Development67> Optimized for current PostgreSQL, MySQL, and SQL Server releases plus migration-first database workflows.89Comprehensive SQL development guidelines combining SQL coding standards, stored procedure generation, and MS SQL Server DBA best practices.1011- Leverage native parallel subagent dispatch and 200k+ context windows where available.121314## Anti-Patterns1516- Using `SELECT *` in production queries: It hides contract drift and pulls more data than the caller needs.17- Writing non-SARGable predicates: Functions on indexed columns turn otherwise cheap queries into table scans.18- Ignoring transaction and lock behavior: Correct SQL needs both logical correctness and concurrency safety.1920## Verification Protocol2122Before claiming "skill applied successfully":23241. Pass/fail: The SQL Development implementation names the target runtime, framework version, and affected files.252. Pass/fail: Build, lint, test, or equivalent local validation is run for the changed surface.263. Pass/fail: Edge cases for errors, dependency drift, and environment differences are addressed or explicitly out of scope.274. Pressure-test scenario: Apply the workflow to a change that passes happy-path tests but fails one boundary condition.285. Success metric: Zero untested success claims; every implementation claim maps to a command or artifact.2930## Before and After Example3132```sql33-- Before34SELECT *35FROM Orders36WHERE YEAR(created_at) = 2026;3738-- After39SELECT order_id, customer_id, created_at, total_amount40FROM Orders41WHERE created_at >= '2026-01-01'42 AND created_at < '2027-01-01';43```4445Uses explicit columns and a SARGable date range so indexes can do their work.4647## Activation Conditions4849Use symptom -> action triggers: when one matches, apply this skill and verify with the protocol below.5051- Writing SQL queries and stored procedures52- Designing database schemas and table structures53- Working with MS SQL Server as a DBA54- Performance tuning and query optimization55- Database backup, restore, and security configuration56- SQL Server 2025+ feature adoption and migration5758---5960## Part 1: Database Schema Design6162### Table Naming63- All table names in singular form64- All column names in singular form6566### Required Columns67- All tables must have a primary key column named `id`68- All tables must have `created_at` for creation timestamp69- All tables must have `updated_at` for last update timestamp7071### Constraints72- All tables must have a primary key constraint73- All foreign key constraints must have a name74- All foreign key constraints defined inline75- All foreign keys must have `ON DELETE CASCADE`76- All foreign keys must have `ON UPDATE CASCADE`77- All foreign keys must reference the primary key of the parent table7879---8081## Part 2: SQL Coding Style8283### Formatting84- Uppercase for SQL keywords (`SELECT`, `FROM`, `WHERE`)85- Consistent indentation for nested queries86- Comments to explain complex logic87- Break long queries into multiple lines88- Organize clauses: `SELECT`, `FROM`, `JOIN`, `WHERE`, `GROUP BY`, `HAVING`, `ORDER BY`8990### Query Structure91- Use explicit column names, never `SELECT *`92- Qualify column names with table alias when using multiple tables93- Prefer JOINs over subqueries when possible94- Include `LIMIT`/`TOP` clauses to restrict result sets95- Use appropriate indexing for frequently queried columns96- Avoid functions on indexed columns in `WHERE` clauses9798---99100## Part 3: Stored Procedure Standards101102### Naming Conventions103- Prefix with `usp_`104- Use PascalCase: `usp_GetCustomerOrders`105- Include plural noun for multiple records: `usp_GetProducts`106- Include singular noun for single record: `usp_GetProduct`107108### Parameter Handling109- Prefix parameters with `@`110- Use camelCase: `@customerId`111- Provide default values for optional parameters112- Validate parameter values before use113- Document parameters with comments114- Required parameters first, optional later115116### Structure117- Include header comment block with description, parameters, return values118- Return standardized error codes/messages119- Return result sets with consistent column order120- Use `OUTPUT` parameters for returning status information121- Prefix temporary tables with `tmp_`122- Include `SET NOCOUNT ON` for data-modifying procedures123124---125126## Part 4: Security Best Practices127128### Query Security129- Parameterize all queries to prevent SQL injection130- Use prepared statements for dynamic SQL131- Avoid embedding credentials in SQL scripts132- Proper error handling without exposing system details133- Avoid dynamic SQL in stored procedures134135### Transaction Management136- Explicitly begin and commit transactions137- Use appropriate isolation levels138- Avoid long-running transactions that lock tables139- Use batch processing for large data operations140141---142143## Part 5: MS SQL Server DBA144145### Tooling146- Install and enable `ms-mssql.mssql` VS Code extension for full database management147- Use official Microsoft documentation for reference and troubleshooting148149### DBA Responsibilities150- Database creation and configuration151- Backup and restore strategies152- Performance tuning and index optimization153- Security management and auditing154- Upgrades and compatibility planning (SQL Server 2025+)155156### Best Practices157- Focus on tool-based database inspection over codebase analysis158- Highlight deprecated/discontinued features in SQL Server 2025+159- Encourage secure, auditable, performance-oriented solutions160- Reference official docs for troubleshooting161- Warn about deprecated features and suggest alternatives162163---164165## Troubleshooting166167| Issue | Solution |168|-------|----------|169| Slow queries | Check execution plan, add indexes, optimize JOINs |170| Deadlocks | Reduce transaction scope, consistent lock ordering |171| Missing data | Verify CASCADE rules, check transaction isolation |172| Permission errors | Review GRANT/REVOKE statements, check role membership |173| Connection issues | Verify firewall rules, connection strings, SQL auth settings |174175---176177## Common Pitfalls178179- Using `SELECT *` in production queries: It hides contract drift and pulls more data than the caller actually needs.180- Writing non-SARGable predicates: Functions on indexed columns turn otherwise cheap queries into table scans.181- Skipping transaction and lock analysis: Correct SQL needs both logical correctness and concurrency safety.182183## References & Resources184185### Documentation186- [T-SQL Patterns](./references/tsql-patterns.md) — MERGE, CTEs, PIVOT, JSON operations, window functions, and error handling187- [Performance Tuning](./references/performance-tuning.md) — Execution plans, index tuning, Query Store, and anti-patterns188189### Scripts190- [Stored Procedure Template](./scripts/stored-proc-template.sql) — Production-ready SP template with TRY/CATCH, pagination, and dynamic sorting191192### Examples193- [Schema Design Example](./examples/schema-design-example.md) — Recipe Management System with 10 tables, stored procedures, and migrations194195---196197<!-- MCP:START -->198199<!-- PORTABILITY:START -->200## Cross-Client Portability201202This skill is written to stay usable across GitHub Copilot, Claude Code, and Codex.203204- GitHub Copilot: keep the folder in a Copilot-visible skill path or wrap the205 workflow in project instructions when folder discovery is unavailable.206- Claude Code: keep the folder in a local skills directory or a compatible plugin source.207- Codex: install or sync the folder into208 `$CODEX_HOME/skills/sql-development` and restart Codex after major changes.209210<!-- PORTABILITY:END -->211212## MCP Availability And Fallback213214Preferred MCP Server: None required215216- Fallback prompt: "Use the SQL Development skill without MCP. Rely on the local `SKILL.md`, bundled references or scripts, and manual verification. Show the exact commands, evidence, and final checks you used before concluding."217- If the current host does not expose a matching server, use the bundled references, scripts, native toolchain, and manual workflow already described in this skill.218- Treat direct local verification, rendered output, logs, tests, or screenshots as the fallback evidence path before completion.219220<!-- MCP:END -->221222## Related Skills223224- [php-development](../php-development/SKILL.md): Use it when the workflow also needs modern PHP backend implementation.225- [powerbi-modeling](../powerbi-modeling/SKILL.md): Use it when the workflow also needs Power BI semantic model design and DAX work.226- [code-quality](../code-quality/SKILL.md): Use it when the workflow also needs two-stage review (spec compliance first, then code quality), maintainability, and refactoring guidance.227- [systematic-debugging](../systematic-debugging/SKILL.md): Use it when the workflow also needs root-cause debugging before proposing fixes.