Created
May 14, 2016 18:04
-
-
Save samirbehara-zz/a72487e936df2d7fc386c0a3bde8903e to your computer and use it in GitHub Desktop.
Compare Execution Plans in SQL Server 2016
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Drop Index if exists | |
DROP INDEX IF EXISTS [idx_Person_Email_Date] ON [Person].[Person] | |
-- Execute a query with a missing index | |
SELECT e.BusinessEntityID FROM HumanResources.Employee e | |
INNER JOIN Person.Person p | |
ON p.ModifiedDate = e.ModifiedDate | |
WHERE p.EmailPromotion = 1 | |
-- Create a Non Clustered Index to optimize query performance | |
CREATE NONCLUSTERED INDEX [idx_Person_Email_Date] | |
ON [Person].[Person] ([EmailPromotion],[ModifiedDate]) | |
-- Execute the select query again to view the difference in Execution Plan | |
SELECT e.BusinessEntityID FROM HumanResources.Employee e | |
INNER JOIN Person.Person p | |
ON p.ModifiedDate = e.ModifiedDate | |
WHERE p.EmailPromotion = 1 | |
-- Generate Execution Plans for both SELECT queries and compare the execution plans in SQL Server 2016. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment