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.
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 its local instructions, bundled resources, standard shell or editor tools, and direct verification. Show the evidence used before concluding."
- Do not claim an MCP operation was used when the active host does not expose it.
- Treat local files, tests, rendered outputs, logs, or screenshots as the fallback evidence path.
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
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 Development
6
7> Optimized for current PostgreSQL, MySQL, and SQL Server releases plus migration-first database workflows.
8
9Comprehensive SQL development guidelines combining SQL coding standards, stored procedure generation, and MS SQL Server DBA best practices.
10
11- Leverage native parallel subagent dispatch and 200k+ context windows where available.
12
13<!-- MCP:START -->
14
15<!-- PORTABILITY:START -->
16## Cross-Client Portability
17
18This skill is written to stay usable across GitHub Copilot, Claude Code, and Codex.
19
20- GitHub Copilot: keep the folder in a Copilot-visible skill path or wrap the
21 workflow in project instructions when folder discovery is unavailable.
22- Claude Code: keep the folder in a local skills directory or a compatible plugin source.
23- Codex: install or sync the folder into
24 `$CODEX_HOME/skills/sql-development` and restart Codex after major changes.
25
26<!-- PORTABILITY:END -->
27
28## MCP Availability And Fallback
29
30Preferred MCP Server: None required
31
32- Fallback prompt: "Use the SQL Development skill without MCP. Rely on its local instructions, bundled resources, standard shell or editor tools, and direct verification. Show the evidence used before concluding."
33- Do not claim an MCP operation was used when the active host does not expose it.
34- Treat local files, tests, rendered outputs, logs, or screenshots as the fallback evidence path.
35
36<!-- MCP:END -->
37
38## Anti-Patterns
39
40- Using `SELECT *` in production queries: It hides contract drift and pulls more data than the caller needs.
41- Writing non-SARGable predicates: Functions on indexed columns turn otherwise cheap queries into table scans.
42- Ignoring transaction and lock behavior: Correct SQL needs both logical correctness and concurrency safety.
43
44## Verification Protocol
45
46Before claiming "skill applied successfully":
47
481. Pass/fail: The SQL Development implementation names the target runtime, framework version, and affected files.
492. Pass/fail: Build, lint, test, or equivalent local validation is run for the changed surface.
503. Pass/fail: Edge cases for errors, dependency drift, and environment differences are addressed or explicitly out of scope.
514. Pressure-test scenario: Apply the workflow to a change that passes happy-path tests but fails one boundary condition.
525. Success metric: Zero untested success claims; every implementation claim maps to a command or artifact.
53
54## Before and After Example
55
56```sql
57-- Before
58SELECT *
59FROM Orders
60WHERE YEAR(created_at) = 2026;
61
62-- After
63SELECT order_id, customer_id, created_at, total_amount
64FROM Orders
65WHERE created_at >= '2026-01-01'
66 AND created_at < '2027-01-01';
67```
68
69Uses explicit columns and a SARGable date range so indexes can do their work.
70
71## Activation Conditions
72
73Use symptom -> action triggers: when one matches, apply this skill and verify with the protocol below.
74
75- Writing SQL queries and stored procedures
76- Designing database schemas and table structures
77- Working with MS SQL Server as a DBA
78- Performance tuning and query optimization
79- Database backup, restore, and security configuration
80- SQL Server 2025+ feature adoption and migration
81
82---
83
84## Part 1: Database Schema Design
85
86### Table Naming
87- All table names in singular form
88- All column names in singular form
89
90### Required Columns
91- All tables must have a primary key column named `id`
92- All tables must have `created_at` for creation timestamp
93- All tables must have `updated_at` for last update timestamp
94
95### Constraints
96- All tables must have a primary key constraint
97- All foreign key constraints must have a name
98- All foreign key constraints defined inline
99- All foreign keys must have `ON DELETE CASCADE`
100- All foreign keys must have `ON UPDATE CASCADE`
101- All foreign keys must reference the primary key of the parent table
102
103---
104
105## Part 2: SQL Coding Style
106
107### Formatting
108- Uppercase for SQL keywords (`SELECT`, `FROM`, `WHERE`)
109- Consistent indentation for nested queries
110- Comments to explain complex logic
111- Break long queries into multiple lines
112- Organize clauses: `SELECT`, `FROM`, `JOIN`, `WHERE`, `GROUP BY`, `HAVING`, `ORDER BY`
113
114### Query Structure
115- Use explicit column names, never `SELECT *`
116- Qualify column names with table alias when using multiple tables
117- Prefer JOINs over subqueries when possible
118- Include `LIMIT`/`TOP` clauses to restrict result sets
119- Use appropriate indexing for frequently queried columns
120- Avoid functions on indexed columns in `WHERE` clauses
121
122---
123
124## Part 3: Stored Procedure Standards
125
126### Naming Conventions
127- Prefix with `usp_`
128- Use PascalCase: `usp_GetCustomerOrders`
129- Include plural noun for multiple records: `usp_GetProducts`
130- Include singular noun for single record: `usp_GetProduct`
131
132### Parameter Handling
133- Prefix parameters with `@`
134- Use camelCase: `@customerId`
135- Provide default values for optional parameters
136- Validate parameter values before use
137- Document parameters with comments
138- Required parameters first, optional later
139
140### Structure
141- Include header comment block with description, parameters, return values
142- Return standardized error codes/messages
143- Return result sets with consistent column order
144- Use `OUTPUT` parameters for returning status information
145- Prefix temporary tables with `tmp_`
146- Include `SET NOCOUNT ON` for data-modifying procedures
147
148---
149
150## Part 4: Security Best Practices
151
152### Query Security
153- Parameterize all queries to prevent SQL injection
154- Use prepared statements for dynamic SQL
155- Avoid embedding credentials in SQL scripts
156- Proper error handling without exposing system details
157- Avoid dynamic SQL in stored procedures
158
159### Transaction Management
160- Explicitly begin and commit transactions
161- Use appropriate isolation levels
162- Avoid long-running transactions that lock tables
163- Use batch processing for large data operations
164
165---
166
167## Part 5: MS SQL Server DBA
168
169### Tooling
170- Install and enable `ms-mssql.mssql` VS Code extension for full database management
171- Use official Microsoft documentation for reference and troubleshooting
172
173### DBA Responsibilities
174- Database creation and configuration
175- Backup and restore strategies
176- Performance tuning and index optimization
177- Security management and auditing
178- Upgrades and compatibility planning (SQL Server 2025+)
179
180### Best Practices
181- Focus on tool-based database inspection over codebase analysis
182- Highlight deprecated/discontinued features in SQL Server 2025+
183- Encourage secure, auditable, performance-oriented solutions
184- Reference official docs for troubleshooting
185- Warn about deprecated features and suggest alternatives
186
187---
188
189## Troubleshooting
190
191| Issue | Solution |
192|-------|----------|
193| Slow queries | Check execution plan, add indexes, optimize JOINs |
194| Deadlocks | Reduce transaction scope, consistent lock ordering |
195| Missing data | Verify CASCADE rules, check transaction isolation |
196| Permission errors | Review GRANT/REVOKE statements, check role membership |
197| Connection issues | Verify firewall rules, connection strings, SQL auth settings |
198
199---
200
201## Common Pitfalls
202
203- Using `SELECT *` in production queries: It hides contract drift and pulls more data than the caller actually needs.
204- Writing non-SARGable predicates: Functions on indexed columns turn otherwise cheap queries into table scans.
205- Skipping transaction and lock analysis: Correct SQL needs both logical correctness and concurrency safety.
206
207## References & Resources
208
209### Documentation
210- [T-SQL Patterns](./references/tsql-patterns.md) — MERGE, CTEs, PIVOT, JSON operations, window functions, and error handling
211- [Performance Tuning](./references/performance-tuning.md) — Execution plans, index tuning, Query Store, and anti-patterns
212
213### Scripts
214- [Stored Procedure Template](./scripts/stored-proc-template.sql) — Production-ready SP template with TRY/CATCH, pagination, and dynamic sorting
215
216### Examples
217- [Schema Design Example](./examples/schema-design-example.md) — Recipe Management System with 10 tables, stored procedures, and migrations
218
219---
220
221## Related Skills
222
223- [php-development](../php-development/SKILL.md): Use it when the workflow also needs modern PHP backend implementation.
224- [powerbi-modeling](../powerbi-modeling/SKILL.md): Use it when the workflow also needs Power BI semantic model design and DAX work.
225- [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.
226- [systematic-debugging](../systematic-debugging/SKILL.md): Use it when the workflow also needs root-cause debugging before proposing fixes.