How to Configure Claude Code SQL Server Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up a claude code sql server prevent delete rule, assign a read-only database user. You can also apply a custom role that blocks delete commands on user tables. Many teams start by giving their AI coding agent a shared admin account. That broad role lets the agent drop tables or delete rows by mistake. A safer setup pairs strict database roles with statement controls during each session. How to set up claude code sql server prevent delete Claude Code reaches external databases through M

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

To set up a claude code sql server prevent delete rule, assign a read-only database user. You can also apply a custom role that blocks delete commands on user tables. Many teams start by giving their AI coding agent a shared admin account. That broad role lets the agent drop tables or delete rows by mistake. A safer setup pairs strict database roles with statement controls during each session.

How to set up claude code sql server prevent delete

Claude Code reaches external databases through Model Context Protocol servers or its Bash tool. Vendor docs advise putting a read-only database user in the connection string. This step ensures the queries that Claude Code runs cannot change your data. On the database side, a database user maps to a server login. For one database, an admin can enable and create a contained user with a password.

SQL Server includes fixed database roles that control how users read and write data. You cannot change the permissions built into these fixed roles. The data reader role lets a user read all data from user tables and views. The data writer role lets a user add, change, or delete data in user tables. The deny data writer role blocks a user from adding, changing, or deleting any data. By contrast, the database owner role can run all maintenance tasks and drop the database.

If the agent only needs to read data, add its user to the data reader role. You can also add the user to the deny data writer role for extra safety. Sometimes an agent needs to insert test rows or update records without deleting anything. Fixed roles cannot split insert and update rights from delete rights on their own. In that case, grant read, insert, and update rights on specific tables instead. Then apply an explicit deny rule for delete actions on those same tables.

What native roles solve and what they leave open

Native SQL Server roles decide who can log in and which table permissions apply. Putting a read-only user in your MCP server setup blocks destructive writes at the database. It also stops raw delete commands sent through the Bash tool when using that account. Even in manual mode, a developer might approve a bad shell command by mistake. Database role limits make sure the engine rejects disallowed deletes from that user.

Claude Code Security + SQL Injection Prevention: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Still, static database roles leave big operational gaps for engineering teams. First, connection strings on developer laptops often hold static passwords that are hard to rotate. Second, a role that allows updates can still ruin data if a query lacks a filter. Third, native read roles let the agent read every column in every user table by default. That means raw emails, phone numbers, card numbers, and national IDs flow into agent context.

Managing agent queries and sensitive data in flight

Database roles only check permissions after the connection starts and the query hits the server. They do not inspect individual statements in flight or pause risky updates for human approval. Teams often want an agent to draft changes while blocking destructive commands before they run. They also need a clear audit log tied to the developer running the agent. Finally, rewriting matched fields like emails or card numbers in results keeps sensitive data safe.

Add runtime guardrails beside SQL Server

Role grants and network rules are needed setup for SQL Server. Still, an allowed user or agent tool can send a bad delete or read raw customer fields over a valid session. In practice, hoop.dev sits inline in the TDS protocol beside the database as a sidecar for your SQL Server. For every query an agent or human runs in production, hoop.dev decides whether to pass, mask, block, or escalate it for review.

With hoop.dev SQL Server controls, rules refuse banned statements before they run, hold risky queries for human review, and mask matched sensitive values in supported result columns in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for HIPAA, PCI DSS, SOX, and GDPR audits. See the source on GitHub.

Frequently asked questions

How does Claude Code reach a SQL Server database?

Claude Code connects to databases through Model Context Protocol servers or by running Bash commands. Vendor docs suggest using a read-only user in the MCP server connection string.

Can a fixed SQL Server role block only delete statements?

No, the fixed deny data writer role blocks inserts, updates, and deletes together. To block only deletes, grant insert and update rights and deny delete rights on tables.

Why avoid giving Claude Code the database owner role?

Members of the database owner role can run all maintenance tasks and drop the database. Giving an AI agent that role risks total data loss from one bad prompt.

The query runs. The emails stay hidden.