Skip to content
Skills Library
Programming · Review & audit

fai-sql-code-review-skill

/fai-sql-code-review-skill

Review SQL code for correctness, performance, security, and maintainability across PostgreSQL, SQL Server, and MySQL. Use when auditing SQL in PRs or reviewing database migration scripts.

Repository
frootai ↗
Licence
MIT
Last repository change
26.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
3
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 26.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Review SQL code for correctness, performance, security, and maintainability across PostgreSQL, SQL Server, and MySQL. Use when auditing SQL in PRs or reviewing database migration scripts.

Original author description

Review SQL code for correctness, performance, security, and maintainability across PostgreSQL, SQL Server, and MySQL. Use when auditing SQL in PRs or reviewing database migration scripts.

How it works

  1. When to Use
  2. Review Checklist
  3. Common Anti-Patterns
  4. Migration Safety
  5. Performance Review
  6. Troubleshooting
  7. Best Practices
  8. Refactoring Safety Checklist
  9. Related Skills
Original SKILL.md headings · 113 lines, 598 words
SKILL.md preview
---
name: fai-sql-code-review-skill
description: |
  Review SQL code for correctness, performance, security, and maintainability
  across PostgreSQL, SQL Server, and MySQL. Use when auditing SQL in PRs
  or reviewing database migration scripts.
---

# SQL Code Review

Review SQL for correctness, performance, security, and maintainability.

## When to Use

- Reviewing PRs with SQL changes
- Auditing stored procedures or migrations
- Checking for SQL injection vulnerabilities
- Validating query performance before deployment

---

## Review Checklist

| Category | Check | Severity |
|----------|-------|----------|
| Security | Parameterized queries (no concatenation) | Blocking |
| Security | Least-privilege GRANT statements | Blocking |
| Performance | No SELECT * in production code | Warning |
| Performance | WHERE clause uses indexed columns | Warning |
| Performance | LIMIT on all unbounded queries | Warning |
| Correctness | UPDATE/DELETE has WHERE clause | Blocking |
| Correctness | Foreign keys have ON DELETE behavior | Warning |
| Maintainability | Consistent naming (snake_case) | Advisory |
| Maintainability | Comments on complex logic | Advisory |

## Common Anti-Patterns

```sql
-- Anti-pattern 1: SQL injection
-- BAD
EXECUTE('SELECT * FROM users WHERE email = ''' + @email + '''')
-- GOOD
SELECT * FROM users WHERE email = @email

-- Anti-pattern 2: SELECT *
-- BAD (fetches unnecessary columns)
SELECT * FROM conversations WHERE user_id = @uid
-- GOOD
SELECT id, title, status FROM conversations WHERE user_id = @uid

-- Anti-pattern 3: Missing index hint
-- BAD (full table scan on millions of rows)
SELECT * FROM messages WHERE content LIKE '%search%'
-- GOOD (use full-text search)
SELECT * FROM messages WHERE CONTAINS(content, 'search')

-- Anti-pattern 4: N+1 query pattern
-- BAD (loop in app code)
FOR EACH conversation: SELECT * FROM messages WHERE conv_id = ?
-- GOOD (single query)
SELECT c.*, m.* FROM conversations c
JOIN messages m ON m.conversation_id = c.id
WHERE c.user_id = @uid
```

## Migration Safety

```sql
-- Safe: ADD COLUMN nullable (no table rewrite)
ALTER TABLE users ADD COLUMN avatar_url VARCHAR(500);

-- Unsafe: ADD NOT NULL without default (blocks writes on large table)
ALTER TABLE users ADD COLUMN avatar_url VARCHAR(500) NOT NULL DEFAULT '';
-- Fix: Add nullable → backfill → add constraint
```

## Performance Review

```sql
-- Always check execution plan for reviewed queries
EXPLAIN ANALYZE [query];
-- Look for: Seq Scan, Nested Loop with high rows, Sort on disk
```

## Troubleshooting

| Issue | Cause | Fix |
|-------|-------|-----|
| SQL injection found | String concatenation | Use parameterized queries |
| Slow migration | Table rewrite on ALTER | Use nullable-first pattern |
| Missing index | No EXPLAIN in review | Require EXPLAIN for new queries |
| Inconsistent naming | No convention | Enforce snake_case in linter |

## Best Practices

| Practice | Rationale |
|----------|-----------|
| Tests before refactoring | Safety net for behavior preservation |
| One refactoring per commit | Easy to revert specific changes |
| No feature changes mixed in | Separate refactor from feature PRs |
| Measure complexity before/after | Prove improvement objectively |
| Small PRs (< 200 lines changed) | Easier to review thoroughly |
| CI must pass after each step | Catch breakage immediately |

## Refactoring Safety Checklist

- [ ] All existing tests pass before starting
- [ ] Each refactoring step committed separately
- [ ] No behavior changes (same inputs → same outputs)
- [ ] All tests still pass after each step
- [ ] Complexity metrics improved
- [ ] PR is under 200 lines of changes

## Related Skills

- `fai-refactor-complexity` — Reduce cyclomatic complexity
- `fai-refactor-plan` — Multi-sprint refactoring plans
- `fai-code-smell-detector` — Automated smell detection
- `fai-review-and-refactor` — Combined review + fix workflow
Files in this package (3)
  • SKILL.lean.md 4 KB
  • SKILL.md 4 KB
  • agents/openai.yaml 1 KB

Versions

The database has no other skills named fai-sql-code-review-skill.

Database snapshot: 13.11.2026 · package version c536be1c0441 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100db-review
    Reviews database schemas, queries, and migrations for correctness, performance, security, and best practices. Use when reviewing SQL migration files or when the user mentions database review, schema review, or query audit.
  • 100code-review
    Review code for correctness, security, performance, and maintainability. Use when the user asks to "review this code", "check my changes", "review PR", "audit", or "what do you think of this approach".
  • 100fai-sql-optimization-skill
    Optimize SQL queries with execution plan analysis, index tuning, query rewriting, and statistics management. Use when diagnosing slow queries across PostgreSQL, SQL Server, or MySQL.
  • 100sql-expert
    Expert-level SQL database design, querying, optimization, and administration across PostgreSQL, MySQL, and SQL Server. Use when the user mentions database, PostgreSQL, MySQL, or query optimization, or when the task involves Database Design, Advanced Queries, Indexes and…
  • 95sql-server
    SQL Server and Azure SQL Database with T-SQL, indexes, stored procedures, and performance optimization patterns. USE WHEN: user mentions "SQL Server", "T-SQL", "MSSQL", "Azure SQL", "SQL Server indexes", "stored procedures", "SQL Server performance" DO NOT USE FOR: PostgreSQL -…
  • 100code-review
    Reviews pull requests and code changes for correctness, conventions, maintainability, performance, test coverage, and security. Use when the user asks for a code review, PR review, feedback on a diff, or to check code quality.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.