🗄️ Fix a Natively Compiled Procedure Rejecting a Hint
Natively compiled stored procedures, used with memory-optimized tables under In-Memory OLTP, support only a restricted subset of T-SQL – and that subset is noticeably narrower when it comes to query and table hints than what an ordinary interpreted procedure allows. A hint that compiles and runs perfectly well in a regular stored procedure can cause the CREATE PROCEDURE (or ALTER PROCEDURE) statement for a natively compiled module to fail outright, because the native compiler rejects it at compile time rather than simply ignoring it – the procedure never gets created at all, let alone executed.
🔎 The Problem
CREATE PROCEDURE dbo.GetActiveOrders
@CustomerId INT
WITH NATIVE_COMPILATION, SCHEMABINDING
AS
BEGIN ATOMIC WITH
(TRANSACTION ISOLATION LEVEL = SNAPSHOT, LANGUAGE = N'us_english')
SELECT OrderId, OrderDate
FROM dbo.Orders
WHERE CustomerId = @CustomerId
OPTION (OPTIMIZE FOR (@CustomerId UNKNOWN)); -- rejected at CREATE time
END
-- Msg 10776, Level 16, State 1
-- Natively compiled stored procedures cannot use query hints or table
-- hints that are not explicitly supported inside a natively compiled
-- module; CREATE PROCEDURE fails to compile at all, before the
-- procedure ever runs even once
✅ Fix: Check the Supported Hint List First
- Check the specific list of hints supported inside natively compiled modules for your SQL Server or Azure SQL version before porting a query hint over verbatim – the supported subset is considerably smaller than what’s allowed in an ordinary interpreted procedure, and it does shift slightly between major versions.
- If the hint existed to steer a specific plan shape, consider whether it’s still needed at all – memory-optimized tables and natively compiled modules use a different, simplified query optimizer internally, and a hint tuned for the regular rowstore optimizer’s behavior may not even address the same concern here.
- If a genuinely unsupported but necessary hint is the blocker, keep that specific query as an ordinary interpreted stored procedure, possibly still reading from the memory-optimized table (which interpreted T-SQL can do without restriction), instead of forcing the entire procedure into native compilation just for its other, simpler statements.
🚨 Why This Is Dangerous
Because the rejection happens at CREATE or ALTER PROCEDURE time rather than at execution time, it’s one of the few T-SQL compatibility issues that can’t be deferred or caught later in testing – but that’s also exactly why it’s easy to assume native compilation support is more complete than it actually is, until the first hint-bearing query you try to port simply refuses to deploy.
Native compilation trades the regular optimizer’s flexibility for raw speed – and the restricted hint surface is part of that trade, not an oversight.



