-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample-script-for-columnstore-index-note.sql
97 lines (75 loc) · 3.19 KB
/
sample-script-for-columnstore-index-note.sql
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
-- ---------------------------------------------
-- #1 叢集資料行存放區索引是否可以與非叢資料列索引並存 ?
-- ---------------------------------------------
CREATE CLUSTERED COLUMNSTORE INDEX [cci_SalesOrderDetail]
ON [dbo].[SalesOrderDetailFromAdventureWorks2017]
GO
CREATE NONCLUSTERED INDEX [ix_SalesOrderDetail_rowguid]
ON [dbo].[SalesOrderDetailFromAdventureWorks2017]([rowguid])
GO
CREATE NONCLUSTERED INDEX [ix_SalesOrderDetail_SalesOrderID]
ON [dbo].[SalesOrderDetailFromAdventureWorks2017]([SalesOrderID])
GO
--DROP INDEX [cci_SalesOrderDetail]
-- ON [dbo].[SalesOrderDetailFromAdventureWorks2017]
--GO
--DROP INDEX [ix_SalesOrderDetail_rowguid]
-- ON [dbo].[SalesOrderDetailFromAdventureWorks2017]
--GO
--DROP INDEX [ix_SalesOrderDetail_SalesOrderID]
-- ON [dbo].[SalesOrderDetailFromAdventureWorks2017]
--GO
-- ---------------------------------------------
-- #2 叢集資料行存放區索引與非叢集資料行存放區索引是否可以並存 ?
-- ---------------------------------------------
CREATE CLUSTERED COLUMNSTORE INDEX [cci_SalesOrderDetail]
ON [dbo].[SalesOrderDetailFromAdventureWorks2017]
GO
CREATE NONCLUSTERED COLUMNSTORE INDEX [nci_SalesOrderDetail_rowguid]
ON [dbo].[SalesOrderDetailFromAdventureWorks2017]([rowguid])
GO
--DROP INDEX [cci_SalesOrderDetail]
-- ON [dbo].[SalesOrderDetailFromAdventureWorks2017]
--GO
-- ---------------------------------------------
-- #3 有叢集資料列索引的資料表可以建立幾個非叢集資料行存放區索引 ?
-- ---------------------------------------------
CREATE CLUSTERED INDEX [pk_SalesOrderDetail]
ON [dbo].[SalesOrderDetailFromAdventureWorks2017]([SalesOrderDetailID])
GO
CREATE NONCLUSTERED COLUMNSTORE INDEX [nci_SalesOrderDetail_rowguid]
ON [dbo].[SalesOrderDetailFromAdventureWorks2017]([rowguid])
GO
--建立第二個 nonclustered columnstore index 會取得下列錯誤訊息
--Msg 35339, Level 16, State 1, Line 50
--Multiple columnstore indexes are not supported.
CREATE NONCLUSTERED COLUMNSTORE INDEX [nci_SalesOrderDetail_SalesOrder]
ON [dbo].[SalesOrderDetailFromAdventureWorks2017]([SalesOrderDetailID],[SalesOrderID])
GO
--DROP INDEX [pk_SalesOrderDetail]
-- ON [dbo].[SalesOrderDetailFromAdventureWorks2017]
--GO
--DROP INDEX [nci_SalesOrderDetail_rowguid]
-- ON [dbo].[SalesOrderDetailFromAdventureWorks2017]
--GO
-- ---------------------------------------------
-- #4 資料表有一個叢集資料列索引的話是否可以直接建立叢集資料行存放區索引 ?
-- ---------------------------------------------
CREATE CLUSTERED INDEX [pk_SalesOrderDetail]
ON [dbo].[SalesOrderDetailFromAdventureWorks2017]([SalesOrderDetailID])
GO
--會取得下列錯誤
--Msg 7999, Level 16, State 9, Line 81
--Could not find any index named 'cci_SalesOrderDetail' for table 'dbo.SalesOrderDetailFromAdventureWorks2017'.
CREATE CLUSTERED COLUMNSTORE INDEX [cci_SalesOrderDetail]
ON [dbo].[SalesOrderDetailFromAdventureWorks2017]
WITH (DROP_EXISTING = ON)
GO
--INDEX 名稱要相同
CREATE CLUSTERED COLUMNSTORE INDEX [pk_SalesOrderDetail]
ON [dbo].[SalesOrderDetailFromAdventureWorks2017]
WITH (DROP_EXISTING = ON)
GO
--DROP INDEX [pk_SalesOrderDetail]
-- ON [dbo].[SalesOrderDetailFromAdventureWorks2017]
--GO