mssql 小技巧

代码1:查看sql的执行时间

SET STATISTICS PROFILE ON 
SET STATISTICS IO ON 
SET STATISTICS TIME ON 

select * from Meeting;

SET STATISTICS PROFILE OFF 
SET STATISTICS IO OFF 
SET STATISTICS TIME OFF


declare @d datetime
set @d=getdate()
/*你的SQL脚本开始*/
select * from Meeting;
/*你的SQL脚本结束*/
select [语句执行花费时间(毫秒)]=datediff(ms,@d,getdate()) 

代码2:创建索引

IF EXISTS (SELECT * FROM SYSINDEXES WHERE NAME='Ix_Meeting_ID')
BEGIN
    DROP INDEX Meeting.Ix_Meeting_ID
END
ELSE
BEGIN
 CREATE CLUSTERED INDEX Ix_Meeting_ID
 ON Meeting(id)  
 WITH FILLFACTOR = 30 
END


/*
UNIQUE--建立唯一索引(UNIQUE索引既可以采用聚集索引结构,也可以采用非聚集索引的结构,如果不指明采用的索引结构,则SQL Server系统默认为采用非聚集索引结构)
CLUSTERED--建立聚集索引
NONCLUSTERED--建立非聚集索引

CREATE CLUSTERED INDEX Ix_Meeting_ID
 ON Meeting(id)  
 WITH FILLFACTOR = 30 --填充因子为30%
*/

 

你可能感兴趣的:(MSSQL)