SQL Server 2008 中的筛选索引示例
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Student1Details]') AND type in (N'U')) DROP TABLE [dbo].Student1Details GO create table Student1Details( [ID] int NOT NULL, [Name] [varchar](50) NULL, [Branch] [varchar](10) NULL, [Location] [varchar](10) NULL constraint [PK_Student1] primary key clustered ( [ID] asc )) on [PRIMARY] insert into Student1Details select 1, 'Nitin', 'CS','IND' union all select 2, 'Ravi', 'EI','ENG' union all select 3, 'Tim', 'ME','US' union all select 4, 'Rick', 'ME','IND' union all select 5, 'Rakesh', 'CS','ABD' union all select 6, 'Tarun', 'ME','IND' union all select 7,'Raushan','IT','IND' select * from Student1Details select ID,Name,Location from Student1Details where Branch='ME' CREATE NONCLUSTERED INDEX index_student1 ON Student1Details(Branch) WHERE Branch = 'ME' select ID,Name,Location from Student1Details where Branch='ME'
在本文中,我将介绍 SQL Server 中的筛选索引,这是 SQL Server 2008 中的一项新功能。
SQL Server 2008 探索了一个新功能 Filtered Index,它是一个优化的非聚集索引,带有 WHERE 子句。 它与其他索引完全不同。 使用筛选索引,可以在明确定义的数据子集而不是 SQL Server 中的整个数据集上创建索引。 对于大多数查询只对特定数据子集感兴趣的非常大的表,这是一个主要优势。
语法
CREATE NONCLUSTERED INDEX index_name ON TableName(Column_Name) WHERE Column_Name = @Column_Value
日期:2020-06-02 22:17:47 来源:oir作者:oir