我正在处理索引,我还是有点新的。我想在现有的Northwind视图上创建一个名为“Products by Category”的索引,该索引基于CategoryName和ProductName列。但是我遇到了一个问题,按类别分类的产品不会让我这样做,因为那里有。名称中有一个空格,但是by会突出显示。无论如何都要让它消失,所以我会停止收到错误。
CREATE INDEX IDX_categoryproducts
ON dbo.Products by catergory (CategoryName,ProductName)
答案 0 :(得分:1)
编辑:刚刚注意到您正在使用Northwind
。您需要更改视图定义以使其可转换为如下所示。
ALTER VIEW [dbo].[Products by Category]
WITH SCHEMABINDING
AS
SELECT Categories.CategoryID,
Categories.CategoryName,
Products.ProductID,
Products.ProductName,
Products.QuantityPerUnit,
Products.UnitsInStock,
Products.Discontinued
FROM dbo.Categories INNER JOIN dbo.Products ON Categories.CategoryID = Products.CategoryID
WHERE Products.Discontinued <> 1
GO
CREATE UNIQUE CLUSTERED INDEX ix ON [dbo].[Products by Category] (CategoryID, ProductID)
CREATE NONCLUSTERED INDEX IDX_categoryproducts ON dbo.[Products by Category] (CategoryName,ProductName)