添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft Edge More info about Internet Explorer and Microsoft Edge

To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation .

Remarks

When SET NOEXEC is ON, SQL Server parses and compiles each batch of Transact-SQL statements but does not execute them. When SET NOEXEC is OFF, all batches are executed after compilation. NOEXEC supports deferred name resolution; if one or more referenced objects in the batch don't exist, no error will be thrown.

The execution of statements in SQL Server has two phases: compilation and execution. This setting is useful for having SQL Server validate the syntax and object names in Transact-SQL code when executing. It is also useful for debugging statements that would generally be part of a larger batch of statements.

The setting of SET NOEXEC is set at execute or run time and not at parse time.

Permissions

Requires membership in the public role.

Examples

The following example uses NOEXEC with a valid query, a query with an object name that is not valid, and a query with incorrect syntax.

USE AdventureWorks2012;  
PRINT 'Valid query';  
-- SET NOEXEC to ON.  
SET NOEXEC ON;  
-- Inner join.  
SELECT e.BusinessEntityID, e.JobTitle, v.Name  
FROM HumanResources.Employee AS e   
   INNER JOIN Purchasing.PurchaseOrderHeader AS poh  
   ON e.BusinessEntityID = poh.EmployeeID  
   INNER JOIN Purchasing.Vendor AS v  
   ON poh.VendorID = v.BusinessEntityID;  
-- SET NOEXEC to OFF.  
SET NOEXEC OFF;  
PRINT 'Invalid object name';  
-- SET NOEXEC to ON.  
SET NOEXEC ON;  
-- Function name used is a reserved keyword.  
USE AdventureWorks2012;  
CREATE FUNCTION dbo.Values(@BusinessEntityID int)  
RETURNS TABLE  
RETURN (SELECT PurchaseOrderID, TotalDue  
   FROM dbo.PurchaseOrderHeader  
   WHERE VendorID = @BusinessEntityID);  
-- SET NOEXEC to OFF.  
SET NOEXEC OFF;  
PRINT 'Invalid syntax';  
-- SET NOEXEC to ON.  
SET NOEXEC ON;  
-- Built-in function incorrectly invoked.  
SELECT *  
FROM fn_helpcollations;  
-- Reset SET NOEXEC to OFF.  
SET NOEXEC OFF;  

See Also

SET Statements (Transact-SQL)
SET SHOWPLAN_ALL (Transact-SQL)
SET SHOWPLAN_TEXT (Transact-SQL)