SET Statements for SQLServer

时间:2014-07-22 23:11:32   收藏:0   阅读:646

SET SHOWPLAN_ALL { ON | OFF }

SET SHOWPLAN_ALL ON;
GO
SELECT BusinessEntityID, JobTitle
FROM HumanResources.Employee
WHERE JobTitle LIKE ‘Production%‘;
GO
SET SHOWPLAN_ALL OFF;
GO

mamicode.com,码迷

All the information in the resultset are estimated, no any actual statistics information.

SET SHOWPLAN_XML { ON | OFF }

SET SHOWPLAN_XML ON;
GO
SELECT BusinessEntityID, JobTitle
FROM HumanResources.Employee
WHERE JobTitle LIKE ‘Production%‘;
GO
SET SHOWPLAN_XML OFF;
GO

mamicode.com,码迷

mamicode.com,码迷

SET SHOWPLAN_TEXT { ON | OFF }

SET SHOWPLAN_TEXT ON;
GO
SELECT BusinessEntityID, JobTitle
FROM HumanResources.Employee
WHERE JobTitle LIKE ‘Production%‘;
GO
SET SHOWPLAN_TEXT OFF;
GO

mamicode.com,码迷

SET STATISTICS PROFILE { ON | OFF }

SET statistics profile ON;
GO
SELECT BusinessEntityID, JobTitle
FROM HumanResources.Employee
WHERE JobTitle LIKE ‘Production%‘;
GO
SET statistics profile OFF;
GO

mamicode.com,码迷
SET STATISTICS XML { ON | OFF }

SET STATISTICS XML ON;
GO
SELECT BusinessEntityID, JobTitle
FROM HumanResources.Employee
WHERE JobTitle LIKE ‘Production%‘;
GO
SET STATISTICS XML OFF;
GO

mamicode.com,码迷

mamicode.com,码迷

SET STATISTICS TIME { ON | OFF }

SET STATISTICS TIME ON;
GO
SELECT BusinessEntityID, JobTitle
FROM HumanResources.Employee
WHERE JobTitle LIKE ‘Production%‘;
GO
SET STATISTICS TIME OFF;
GO

mamicode.com,码迷

SET STATISTICS IO { ON | OFF }

SET STATISTICS IO ON;
GO
SELECT BusinessEntityID, JobTitle
FROM HumanResources.Employee
WHERE JobTitle LIKE ‘Production%‘;
GO
SET STATISTICS IO OFF;
GO

mamicode.com,码迷

SET FORCEPLAN { ON | OFF }

USE AdventureWorks2012;
GO
-- Make sure FORCEPLAN is set to OFF.
SET SHOWPLAN_TEXT OFF;
GO
SET FORCEPLAN OFF;
GO
SET SHOWPLAN_TEXT ON;
GO
-- Example where the query plan is not forced.
SELECT p.LastName, p.FirstName, v.Name
FROM Person.Person AS p
   INNER JOIN HumanResources.Employee AS e
   ON e.BusinessEntityID = p.BusinessEntityID
   INNER JOIN Purchasing.PurchaseOrderHeader AS poh
   ON e.BusinessEntityID = poh.EmployeeID
   INNER JOIN Purchasing.Vendor AS v
   ON poh.VendorID = v.BusinessEntityID;
GO
-- SET FORCEPLAN to ON.
SET SHOWPLAN_TEXT OFF;
GO
SET FORCEPLAN ON;
GO
SET SHOWPLAN_TEXT ON;
GO
-- Reexecute inner join to see the effect of SET FORCEPLAN ON.
SELECT p.LastName, p.FirstName, v.Name
FROM Person.Person AS p
   INNER JOIN HumanResources.Employee AS e 
   ON e.BusinessEntityID = p.BusinessEntityID
   INNER JOIN Purchasing.PurchaseOrderHeader AS poh
   ON e.BusinessEntityID = poh.EmployeeID
   INNER JOIN Purchasing.Vendor AS v
   ON poh.VendorID = v.BusinessEntityID;
GO
SET SHOWPLAN_TEXT OFF;
GO
SET FORCEPLAN OFF;
GO

mamicode.com,码迷


DBCC DROPCLEANBUFFERS 清除数据缓存
DBCC FREEPROCCACHE  清除执行计划缓存

REFERENCES

SET SHOWPLAN_XML
http://technet.microsoft.com/en-us/library/ms187757.aspx

SET SHOWPLAN_TEXT 

http://technet.microsoft.com/en-us/library/ms176058.aspx

SET SHOWPLAN_ALL

http://technet.microsoft.com/en-us/library/ms187735.aspx

SET STATISTICS PROFILE

http://technet.microsoft.com/en-us/library/ms188752.aspx

SET STATISTICS XML
http://technet.microsoft.com/en-us/library/ms176107.aspx

SET STATISTICS TIME 
http://technet.microsoft.com/en-us/library/ms190287.aspx
SET STATISTICS IO
http://technet.microsoft.com/en-us/library/ms184361.aspx
SET FORCEPLAN
http://technet.microsoft.com/en-us/library/ms188344.aspx
SET Statements (Transact-SQL)
http://msdn.microsoft.com/en-us/library/ms190356.aspx

SET Statements for SQLServer,码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!