首页 > 代码库 > sql【索引操作】

sql【索引操作】

语法:CREATE [索引类型] INDEX 索引名称ON 表名(列名)WITH FILLFACTOR = 填充因子值0~100GO/*实例*/   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= 30GO 查询测试/*-----指定按索引IX_writtenExam 查询----*/declare @startTime datetimeSET @startTime = GETDATE();SELECT sum(ID) FROM testtable with (INDEX=IX_writtenExam)declare @endtime datetimeSET @endtime = GETDATE();print datediff(ms,@startTime,@endtime)SELECT sum(ID) FROM testtable  添加数据SET IDENTITY_INSERT TestTable ONdeclare @i intset @i=1while @i<=400000begin    insert into TestTable([id], FirstName, LastName, Country,Note) values(@i, FirstName_XXX,LastName_XXX,Country_XXX,Note_XXX)    set @i=@i+1endSET IDENTITY_INSERT TestTable OFF

 

sql【索引操作】