How to Fix SQL Server Error 10536 (Msg 10536)
You see sql server error 10536 when a plan guide batch has too many statements. You fix it by targeting one statement in the cache or writing a standard guide. Database teams use plan guides to shape query execution without changing app source code. When the engine hits this severity 16 error, it stops the guide creation right away. Your live queries still run, but they keep using the old plan from the cache. Let us look at why the engine rejects the handle and how to fix it. What causes sql
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.
You see sql server error 10536 when a plan guide batch has too many statements. You fix it by targeting one statement in the cache or writing a standard guide.
Database teams use plan guides to shape query execution without changing app source code. When the engine hits this severity 16 error, it stops the guide creation right away. Your live queries still run, but they keep using the old plan from the cache. Let us look at why the engine rejects the handle and how to fix it.
What causes sql server error 10536 in the database engine
The database engine throws message 10536 with a severity level of 16. The message says the engine cannot create the plan guide for your chosen name. This happens because the batch or module for your plan handle has too many statements.
When an app sends a query batch, the engine stores that plan in memory. Each cached plan gets a unique handle that identifies the whole batch or stored module. Admins often freeze a good plan by creating a plan guide from that memory handle. Still, a single batch or module can hold dozens of separate query statements inside it.
If you do not pick a specific statement offset, the engine tries to cover everything. When the batch exceeds the statement limit for handle-based guides, the engine blocks the action. Severity 16 means the user made a rule mistake that the admin must fix. It does not mean the server is crashing or that disk data is corrupt.
How to diagnose and fix the failure in production
To fix this error, first inspect the cached batch linked to your plan handle. Query the system views to see every statement stored inside that single plan handle. Look for the exact slow query statement that needs the plan guide in production. Note the starting byte offset for that single statement inside the larger query batch.
Next, run the plan guide creation step again and pass that exact statement offset. This tells the engine to bind the guide to one query, not the whole batch. If you truly need guides for several queries in the batch, make separate plan guides. Each guide will target one statement offset from that same plan handle in memory.
Kubernetes API Server Access + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
You can also build a text-based plan guide instead of pulling from the plan cache. Match the exact statement text and attach the query hints your team wants to use. Always test the new guide in a staging database before changing a live system.
How to keep database permissions safe during fixes
Fixing query plans in production requires strong security rules and tight user role scoping. Never hand out broad admin rights to developers who only need to inspect query plans. In SQL Server, a database user is the identity of a login inside a database. People who use many databases often get a user tied to a master login. For one or a few databases, admins can set up a contained database user instead. The admin must enable contained databases on the server and the target database first.
Watch out for fixed database roles when you grant access to your tuning team. The permissions assigned to fixed database roles cannot be changed by an admin. For example, members of the owner role can do all setup and maintenance tasks. They can even drop the whole database in SQL Server, which carries huge risk. Members of the data reader role can read all data from all user tables. If a table holds emails, phone numbers, card numbers, or national IDs, readers see them. Instead, use data masking so the system rewrites matched fields in query results. Grant only the exact metadata rights needed to view query plans and test fixes.
Check SQL Server batches and results on the wire
SQL Server logins and roles decide who connects. They do not check what each TDS batch does or mask sensitive values in returned rows. With hoop.dev, you run an open-source proxy, a sidecar for your SQL Server, inline in the TDS wire protocol. On every batch an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
Before a batch hits the server, hoop.dev guardrails refuse disallowed actions with a native TDS error or hold risky statements for approval. On the way back, hoop.dev data masking rewrites sensitive values in supported result columns in memory, and every decision is logged. Explore the MIT-licensed project on GitHub.
Frequently asked questions
Does sql server error 10536 stop running queries?
No, severity 16 errors only stop the plan guide creation command you just ran. Your app queries will keep running with their current execution plans in the cache.
Can I change fixed role rights to let developers tune queries?
No, the permissions assigned to fixed database roles cannot be changed in SQL Server. You must create a custom role if you need a narrow set of tuning permissions.
Why should we avoid giving the owner role during query fixes?
Members of the owner role can run all maintenance tasks and drop the database. Always grant smaller roles so a mistake during query tuning does not delete live data.
Related guides
In this post