是否有任何硬性规定来决定应将哪些列以及应以什么顺序放入非聚集索引中。我只是在阅读这篇文章https://stackoverflow.com/questions/1307990/why-use-the-include-clause-when-creating-an-index ,我发现对于以下查询:
SELECT EmployeeID, DepartmentID, LastName
FROM Employee
WHERE DepartmentID = 5
张贴者建议制作这样的索引:
CREATE NONCLUSTERED INDEX NC_EmpDep
ON Employee(EmployeeID, DepartmentID)
INCLUDE (Lastname)
这是我的问题,为什么我们不能像这样做索引
CREATE NONCLUSTERED INDEX NC_EmpDep
ON Employee( EmployeeID, DepartmentID, LastName)
要么
CREATE NONCLUSTERED INDEX NC_EmpDep
ON Employee( EmployeeID, LastName)
INCLUDE (DepartmentID)
什么原因导致发布者决定保留“姓氏”列。为什么不另列?以及如何决定应以什么顺序将列保留在那里?