创建索引:(学生学号创建聚集索引)
create unique clustered index IX_student_ID on student(studentid)
规则:
create(unique)(clustered)(nonclustered)index 索引名 on 表名/视图名(索引列名,(asc/desc))
(with pad_index,fillfactor=填充因子值)drop_existing
unique 唯一索引
clustered 聚集索引
nonclustered 非聚集索引
asc 升序,desc降序
pad_index 每个索引页留出空间
fillfactor 该页面填充宽度
drop_existing 删除已存在同名索引
索引命名:IX_表名_列名
组合索引:
create unique clustered index IX_grade_studentid_courseid on grade(studentid,courseid)
查看索引:
exec sp_helpindex 表名
删除索引:
drop index 表名.索引名(视图.索引名)
drop index student.IX_student_Name
索引分析:
set showplan_All(on/off)
set showplan_text(on/off)
处理器执行每个语句采用步骤
setshowplan_All on go
select studentid,studentname,birthday from student as s inner join class as c
on s.classid=c.class id go
set showplan_All of go
花费磁盘活动量统计:
set statistics IN on/off
同上
查看碎片:
DBCC showcontic(表名,表id,视图名,视图id,索引名,索引id)
DBCC showcontic(student)
维护重建索引:
(影响用户使用)
drop_existing
Alter index IX_student_classid(索引名/all)
on student(表名视图名)
reorganize
(不影响用户使用)
Alter index IX_class_classid
on class
rebuild
查看统计信息:
DBCC show_statistics(student,pk_student)(表名,索引名)
创建统计信息:
create statistics 统计信息名on表名视图名(列)
更新统计信息:
update statistics表名(统计信息名)
create unique clustered index IX_student_ID on student(studentid)
规则:
create(unique)(clustered)(nonclustered)index 索引名 on 表名/视图名(索引列名,(asc/desc))
(with pad_index,fillfactor=填充因子值)drop_existing
unique 唯一索引
clustered 聚集索引
nonclustered 非聚集索引
asc 升序,desc降序
pad_index 每个索引页留出空间
fillfactor 该页面填充宽度
drop_existing 删除已存在同名索引
索引命名:IX_表名_列名
组合索引:
create unique clustered index IX_grade_studentid_courseid on grade(studentid,courseid)
查看索引:
exec sp_helpindex 表名
删除索引:
drop index 表名.索引名(视图.索引名)
drop index student.IX_student_Name
索引分析:
set showplan_All(on/off)
set showplan_text(on/off)
处理器执行每个语句采用步骤
setshowplan_All on go
select studentid,studentname,birthday from student as s inner join class as c
on s.classid=c.class id go
set showplan_All of go
花费磁盘活动量统计:
set statistics IN on/off
同上
查看碎片:
DBCC showcontic(表名,表id,视图名,视图id,索引名,索引id)
DBCC showcontic(student)
维护重建索引:
(影响用户使用)
drop_existing
Alter index IX_student_classid(索引名/all)
on student(表名视图名)
reorganize
(不影响用户使用)
Alter index IX_class_classid
on class
rebuild
查看统计信息:
DBCC show_statistics(student,pk_student)(表名,索引名)
创建统计信息:
create statistics 统计信息名on表名视图名(列)
更新统计信息:
update statistics表名(统计信息名)