sql【索引操作】
语法: 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=@i+1 end SET IDENTITY_INSERT TestTable OFF
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。