SET NOEXEC (Transact-SQL)SET NOEXEC (Transact-SQL)

適用於: 是SQL Server (從 2008 開始) 是Azure SQL Database 否Azure SQL 資料倉儲 否平行處理資料倉儲 APPLIES TO: yesSQL Server (starting with 2008) yesAzure SQL Database noAzure SQL Data Warehouse noParallel Data Warehouse

編譯每項查詢,但不執行它。Compiles each query but does not execute it.

主題連結圖示 Transact-SQL 語法慣例Topic link icon Transact-SQL Syntax Conventions

語法Syntax

  
SET NOEXEC { ON | OFF }  

RemarksRemarks

當 SET NOEXEC 是 ON 時,SQL ServerSQL Server 會編譯 Transact-SQLTransact-SQL 陳述式的每個批次,但不會執行它們。When SET NOEXEC is ON, SQL ServerSQL Server compiles each batch of Transact-SQLTransact-SQL statements but does not execute them. 當 SET NOEXEC 是 OFF 時,就會在編譯之後執行所有批次。When SET NOEXEC is OFF, all batches are executed after compilation.

SQL ServerSQL Server 中執行陳述式有兩個階段:編譯和執行。The execution of statements in SQL ServerSQL Server has two phases: compilation and execution. 在執行時,這項設定可用來使 SQL ServerSQL Server 驗證 Transact-SQLTransact-SQL 程式碼中的語法和物件名稱。This setting is useful for having SQL ServerSQL Server validate the syntax and object names in Transact-SQLTransact-SQL code when executing. 它也可用來偵錯通常是在較大的陳述式批次中的陳述式。It is also useful for debugging statements that would generally be part of a larger batch of statements.

SET NOEXEC 的設定是在執行階段進行設定,而不是在剖析階段進行設定。The setting of SET NOEXEC is set at execute or run time and not at parse time.

[權限]Permissions

需要 public 角色中的成員資格。Requires membership in the public role.

範例Examples

下列範例搭配有效的查詢、含無效物件名稱的查詢,以及語法不正確的查詢來使用 NOEXECThe 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;  
GO  
PRINT 'Valid query';  
GO  
-- SET NOEXEC to ON.  
SET NOEXEC ON;  
GO  
-- 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;  
GO  
-- SET NOEXEC to OFF.  
SET NOEXEC OFF;  
GO  
  
PRINT 'Invalid object name';  
GO  
-- SET NOEXEC to ON.  
SET NOEXEC ON;  
GO  
-- Function name uses is a reserved keyword.  
USE AdventureWorks2012;  
GO  
CREATE FUNCTION dbo.Values(@BusinessEntityID int)  
RETURNS TABLE  
AS  
RETURN (SELECT PurchaseOrderID, TotalDue  
   FROM dbo.PurchaseOrderHeader  
   WHERE VendorID = @BusinessEntityID);  
  
-- SET NOEXEC to OFF.  
SET NOEXEC OFF;  
GO  
  
PRINT 'Invalid syntax';  
GO  
-- SET NOEXEC to ON.  
SET NOEXEC ON;  
GO  
-- Built-in function incorrectly invoked.  
SELECT *  
FROM fn_helpcollations;  
-- Reset SET NOEXEC to OFF.  
SET NOEXEC OFF;  
GO  

另請參閱See Also

SET 陳述式 (Transact-SQL) SET Statements (Transact-SQL)
SET SHOWPLAN_ALL (Transact-SQL) SET SHOWPLAN_ALL (Transact-SQL)
SET SHOWPLAN_TEXT (Transact-SQL)SET SHOWPLAN_TEXT (Transact-SQL)