{"success":true,"name":"wrap-multi-step-sql-writes-in-a-transaction","description":"Writing SQL code that does several INSERTs or UPDATEs for one operation.","category":"ai-brimind","path":"ai-brimind/wrap-multi-step-sql-writes-in-a-transaction/SKILL.md","file":"SKILL.md","content":"---\nname: wrap-multi-step-sql-writes-in-a-transaction\ndescription: \"Writing SQL code that does several INSERTs or UPDATEs for one operation.\"\n---\n\n# Wrap Multi-Step SQL Writes in a Transaction\n\n## When to use\nProject uses SQL, and one logical action (an order, a transfer, a signup) requires two or more write statements to complete.\n\n## Example request\nInsert order then insert order items → crash between them leaves an empty order; the two writes are one unit. Deduct stock then create shipment → second one fails and stock is lost; that is a partial write. Retrying failed steps manually in code → the database already solves this; BEGIN/COMMIT/ROLLBACK is the built-in mechanism. Two users updating the same row → last write silently wins; transactions plus row locking exist for exactly this.\n\n## Instructions\nAct like a developer who thinks in units of work, not individual statements. Before writing the code: list every statement that must succeed together for the operation to be correct, and state what broken state remains if execution stops halfway. If any partial state is unacceptable, wrap the statements in a single transaction and roll back on any error — do not hand-roll cleanup logic the database already provides. Check what your ORM or driver does by default; many auto-commit each statement. Only ship the code once you can explain why either everything commits or nothing does, and what happens on a failure at each step.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1024\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}