Changing rows through the sql-server write tool with a counted expectedRows and a person's approval. Use when inserting, updating, deleting or merging rows on a sql-server registration, or a write rolled back or its outcome is unknown. Not for reads: the query-safely skill.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Write Rows?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/melodic-software-write-rows)
---
name: write-rows
description: "Changing rows through the sql-server write tool with a counted expectedRows and a person's approval. Use when inserting, updating, deleting or merging rows on a sql-server registration, or a write rolled back or its outcome is unknown. Not for reads: the query-safely skill."
disable-model-invocation: false
---
# Write rows
## Preconditions
- `write` runs only on a registration started with `--write`, against an environment whose write
block names a write login and whose write mode is on. `describe_environments` shows the write
mode and the most rows one write may expect. When writes are off there, tell the person:
opening them is their change to the registration or the config.
- Use the environment and database settled with the choose-environment skill. A write must
name its database when the environment allows more than one, and a pattern counts as more than
one.
- A change of several statements that must land together goes to the run-scripts skill, never
to a run of `write` calls: each `write` call commits on its own.
## Workflow
- Write one INSERT, UPDATE, DELETE or MERGE, optionally led by WITH. The `write` tool's own
description lists what it refuses.
- Count the rows first with `query`, using the exact filter the write will use. That count is
`expectedRows`: the write commits only when the statement affects exactly that many rows of the
target table, and rolls back otherwise. Never choose the number to fit whatever the statement
happens to do.
- Run `preview_write` on the target table. It lists the triggers on the table and the foreign keys
whose delete or update action cascades from it. The row check counts only the target table, so
rows a trigger or cascade changes are not counted and only this preview shows them.
- Before the call, show the person the environment, the database, the statement, `expectedRows`
with the query that counted it, and what `preview_write` listed. A person approves every `write`
call, and this is what they need to judge it.
- When the count is above the most the environment lets one write expect, split the write by key
into calls that each stay within it.
## Outcomes
- Committed: report `committed` and `rowCount`.
- A row-count mismatch rolls back and returns an error naming both counts, so nothing changed.
Find out why the counts differ (the filter, a concurrent change, a trigger) and show the person
before any new attempt.
- After a timeout, or when a trigger returns more rows than the row cap, whether the write
committed is not known. Read the table to learn its state and tell the person before anything
else; never resend the write blind.
- On a refusal, read the message and do its `next` step. On any other error, report the message
to the person.
## Next
- The write committed and the person wants the result checked: the query-safely skill.
- The change needs several statements to land together: the run-scripts skill.
## Related
- No sql-server registration is available, or a call reports that the config is invalid: the setup skill.
## Gotchas
- A sequence of `write` calls is not one transaction. When a later call fails, the earlier ones
have already committed; a change that must land whole belongs in a script.
- Leaving out `database` on an environment with several databases or a pattern is refused for a
write, even where a read without it would run in the default database.