Skip to content

Instantly share code, notes, and snippets.

@samirbehara-zz
Created May 14, 2016 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samirbehara-zz/a72487e936df2d7fc386c0a3bde8903e to your computer and use it in GitHub Desktop.
Save samirbehara-zz/a72487e936df2d7fc386c0a3bde8903e to your computer and use it in GitHub Desktop.
Compare Execution Plans in SQL Server 2016
-- 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