语法: CREATE [索引类型] INDEX 索引名称 ON 表名(列名) WITH FILLFACTOR = 填充因子值0~100 GO /*实例*/ CREATE NONCLUSTERED INDEX Index_NotePage_ShareState --创建一个非聚集索引 ON NDB.dbo.NotePage(ShareState) --为TEST表的TNAME字段创建索引 WITH FILLFACTOR = 30 --填充因子为30% GO 添加索引 IF EXISTS (SELECT name FROM sysindexes WHERE name = ‘IX_writtenExam‘) DROP INDEX testtable.IX_writtenExam /*--笔试列创建非聚集索引:填充因子为%--*/ CREATE NONCLUSTERED INDEX IX_writtenExam ON testtable(id) WITH FILLFACTOR= 30 GO 查询测试 /*-----指定按索引IX_writtenExam 查询----*/ declare @startTime datetime SET @startTime = GETDATE(); SELECT sum(ID) FROM testtable with (INDEX=IX_writtenExam) declare @endtime datetime SET @endtime = GETDATE(); print datediff(ms,@startTime,@endtime) SELECT sum(ID) FROM testtable 添加数据 SET IDENTITY_INSERT TestTable ON declare @i int set @i=1 while @i<=400000 begin insert into TestTable([id], FirstName, LastName, Country,Note) values(@i, ‘FirstName_XXX‘,‘LastName_XXX‘,‘Country_XXX‘,‘Note_XXX‘) set @i[email protected]+1 end SET IDENTITY_INSERT TestTable OFF
时间: 2024-10-10 04:34:26