Creating Natively Compiled Stored Procedures
Creating Natively Compiled Stored Procedures
aspx
THIS TOPIC APPLIES TO: SQL Server (starting with 2016) Azure SQL Database Azure SQL Data Warehouse
Parallel Data Warehouse
Natively compiled stored procedures do not implement the full Transact-SQL programmability and query surface area. There
are certain Transact-SQL constructs that cannot be used inside natively compiled stored procedures. For more information,
see Supported Features for Natively Compiled T-SQL Modules.
There are, however, several Transact-SQL features that are only supported for natively compiled stored procedures:
NOT NULL constraints on parameters of and variables in natively compiled stored procedures. You cannot assign
NULL values to parameters or variables declared as NOT NULL. For more information, see DECLARE @local_variable
(Transact-SQL).
Natively compiled stored procedures are created using CREATE PROCEDURE (Transact-SQL). The following example shows a
memory-optimized table and a natively compiled stored procedure used for inserting rows into the table.
Transact-SQL
1 of 2 3/10/2017 10:36 AM
Creating Natively Compiled Stored Procedures https://msdn.microsoft.com/en-us/library/dn452286(d=printer).aspx
In the code sample, NATIVE_COMPILATION indicates that this Transact-SQL stored procedure is a natively compiled stored
procedure. The following options are required:
Option Description
SCHEMABINDING A natively compiled stored procedure must be bound to the schema of the objects it references.
This means that tables referenced by the procedure cannot be dropped. Tables referenced in the
procedure must include their schema name, and wildcards (*) are not allowed in queries (meaning
no SELECT * from...). SCHEMABINDING is only supported for natively compiled stored
procedures in this version of SQL Server.
BEGIN ATOMIC The natively compiled stored procedure body must consist of exactly one atomic block. Atomic
blocks guarantee atomic execution of the stored procedure. If the procedure is invoked outside the
context of an active transaction, it will start a new transaction, which commits at the end of the
atomic block. Atomic blocks in natively compiled stored procedures have two required options:
TRANSACTION ISOLATION LEVEL. See Transaction Isolation Levels for Memory-Optimized Tables
for supported isolation levels.
LANGUAGE. The language for the stored procedure must be set to one of the available languages
or language aliases.
See Also
Natively Compiled Stored Procedures
Community Additions
© 2017 Microsoft
2 of 2 3/10/2017 10:36 AM