sql-review
БесплатноБез исполняемых скриптовНе проверенReviewing SQL - what to flag, and what the database and linters actually check for you USE WHEN: you are reviewing, critiquing or auditing existing SQL - a…
от claude-dev-suite★ 51 звезда на GitHubОб этом скилле
Reviewing SQL
A reviewer's leverage is what the toolchain cannot say — and in SQL that is
almost everything. There is no type checker for query meaning: the parser
accepts anything well-formed, and sqlfluff checks layout and naming, not
correctness. A query that returns the wrong rows and a query that returns the
right ones are equally valid to every tool in the pipeline.
So this skill is longer on checks and shorter on "already covered" than any other in the review category. Three themes carry most of it:
- NULL is not a value, and three-valued logic silently changes results.
- A query is correct only under the isolation level it actually runs at.
- The plan, not the text, decides the cost — and small edits change plans.
The snippets are fragments cut down to the defect, not runnable programs.
Already covered - do not spend review on it
| Defect | Reported by |
|---|---|
| Syntax error, unknown column or table | the database, at parse or prepare time |
| Type mismatch in a comparison | the database — but many engines coerce silently instead |
| Layout, capitalisation, alias naming | sqlfluff (style rules only) |
A missing NOT NULL or foreign key |
nothing — unless the migration adds it |
| A query that is slow | nothing, until production; EXPLAIN tells you only if someone runs it |
That table is short on purpose. Assume nothing checked the meaning of this query, because nothing did.
NULL and three-valued logic
NOT IN against anything nullable
SELECT * FROM orders
WHERE customer_id NOT IN (SELECT id FROM banned); -- one NULL in `banned` returns ZERO rows
When you see it: NOT IN (subquery) where the subquery column is not
declared NOT NULL.
Ask: can that column be NULL? x NOT IN (1, NULL) evaluates to UNKNOWN, not
TRUE, so the row is filtered out — every row. The query returns an empty set and
looks like a data problem. NOT EXISTS has the semantics people expect here,
and it is also usually the better plan.
An aggregate that silently skips NULLs
SELECT AVG(rating) FROM reviews; -- ignores NULL ratings entirely
SELECT COUNT(rating) FROM reviews; -- not the row count
When you see it: AVG, SUM, COUNT(column) on a nullable column,
especially when the result is presented as "the average" of something.
Ask: is skipping the missing values the intended definition? COUNT(*) and
COUNT(col) differ exactly here, and the difference is invisible until some
rows are NULL.
<> excluding rows that should match
SELECT * FROM users WHERE status <> 'banned'; -- rows with NULL status are excluded
When you see it: any inequality on a nullable column.
Ask: should NULL rows appear? Comparison with NULL is UNKNOWN, so they are
dropped from both = 'banned' and <> 'banned'. That is often not what the
sentence in the ticket said.
Concurrency and transactions
Read-modify-write with no lock
SELECT balance FROM accounts WHERE id = 1; -- app subtracts
UPDATE accounts SET balance = 90 WHERE id = 1; -- last writer wins
When you see it: a SELECT whose value is computed on and written back,
across two statements.
Ask: what happens with two concurrent callers? Both read 100, both write 90,
one debit disappears. Correct in every test that runs single-threaded. The fixes
are SELECT ... FOR UPDATE, an atomic UPDATE ... SET balance = balance - 10,
or an optimistic version column — and they differ in what they cost.
An assumption that only holds at a higher isolation level
BEGIN;
SELECT COUNT(*) FROM seats WHERE event = 1 AND free; -- 1
-- another transaction books it here
INSERT INTO bookings VALUES (...); -- oversold
COMMIT;
When you see it: a check-then-act inside a transaction; any invariant enforced by reading before writing.
Ask: which isolation level does this connection use? The default is READ COMMITTED in PostgreSQL, SQL Server and Oracle, and REPEATABLE READ in MySQL — none of which prevents this. Only SERIALIZABLE does, and then the code must handle serialisation failures by retrying. A unique constraint is usually the cheaper answer.
A migration that locks a large table
ALTER TABLE orders ADD COLUMN status text NOT NULL DEFAULT 'new';
CREATE INDEX idx_orders_user ON orders(user_id);
When you see it: DDL in a migration against a table that is large in production.
Ask: how long does this hold its lock, and on what? Adding a NOT NULL
column with a default rewrites the whole table on older PostgreSQL (fixed in 11)
and on MySQL depending on the algorithm. CREATE INDEX blocks writes unless it
is CONCURRENTLY — which in turn cannot run inside a transaction, so the
migration tool has to be told.
Plans, indexes and cost
A predicate that disables the index
WHERE DATE(created_at) = '2026-01-01' -- function on the column: no index use
Установить sql-review в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobFAQ
Что делает скилл sql-review?
Reviewing SQL - what to flag, and what the database and linters actually check for you USE WHEN: you are reviewing, critiquing or auditing existing SQL - a "code review" of a query, a migration, a stored procedure, a view, or ORM-generated SQL in a diff or a PR; deciding what to comment on in SQL; judging whether a query is correct under concurrency and at scale DO NOT USE FOR: writing or learning SQL - use `databases/sql-fundamentals` or `databases/sql-advanced`; vendor-specific tuning - use the PostgreSQL, MySQL, Oracle or SQL Server skills; schema migration mechanics - use `databases/migrations` and `databases/flyway`
Как установить скилл sql-review?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл sql-review запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic