数据库 索引 【vaynexiao】

1,最常见的sql优化方法
2,相当于书的目录
3,表的主键在创建时会自动创建一个主键索引
4,占用存储空间,所以并不是越多越好

聚焦索引(比如主键索引)、最多一个
非聚焦索引(比如唯一索引)可以多个
在这里插入图片描述

–1,默认非聚集nonclustered
create index index_username
on oams_attr_workhours(username)
with(
drop_existing=off --已存在时是否删除
);
–2,聚集
create clustered index index_username2
on oams_attr_workhours(username)
with(
drop_existing=off --已存在时是否删除
);
–3,非聚集
create unique nonclustered index un_workhours
on oams_attr_workhours(usercode,username,rz_c_bpmdm,datetime,report_date)
with(
pad_index=on, --使用填充因子时才会生效
fillfactor=50, – 指定创建索引时,每个索引页的数据占索引页百分比
ignore_dup_key=on --违反约束时失败,并回滚
) --报错:有重复是因为选择的字段组合有重复
–读写比100:1 100
–读写各一半80 (读越大因子越大)
–读小于写 50-70
–4,删除索引
drop index index_username on oams_attr_workhours

发布了75 篇原创文章 · 获赞 106 · 访问量 16万+

猜你喜欢

转载自blog.csdn.net/vayne_xiao/article/details/105321111