-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilterIndex.sql
More file actions
36 lines (29 loc) · 985 Bytes
/
Copy pathFilterIndex.sql
File metadata and controls
36 lines (29 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
--find SalesOrderDetailIDs with UnitPrice > 2000
SELECT SalesOrderDetailID, UnitPrice
FROM Sales.SalesOrderDetail
WHERE UnitPrice > 2000
GO
--add nonclustered index to UnitPrice column
CREATE NONCLUSTERED INDEX NCI_SalesOrderDetail_UnitPrice
ON Sales.SalesOrderDetail (UnitPrice)
GO
--find SalesOrderDetailIDs with UnitPrice > $2000 - no index
SELECT SalesOrderDetailID, UnitPrice
FROM Sales.SalesOrderDetail
WHERE UnitPrice > 2000
GO
--find SalesOrderDetailIDs with UnitPrice > $2000 - using nonclustered index
SELECT SalesOrderDetailID, UnitPrice
FROM Sales.SalesOrderDetail
WHERE UnitPrice > 2000
GO
--add nonclustered filtered index to UnitPrice column
CREATE NONCLUSTERED INDEX fIX_SalesOrderDetail_UnitPrice
ON AdventureWorks2012.Sales.SalesOrderDetail(UnitPrice)
WHERE UnitPrice > 1000
GO
--find SalesOrderDetailIDs with UnitPrice > 2000 - now using nonclustered filtered index
SELECT SalesOrderDetailID, UnitPrice
FROM Sales.SalesOrderDetail
WHERE UnitPrice > 2000
GO