SQL视图和索引

--创建视图
create view v_tmoney
as
select userid,username from t_money
go

select * from v_tmoney


--创建索引原则:
--1该列用于平凡搜索
--2该列用于排序
--请不要对下面的列创建索引
--1列中仅包含几个不同的值
--2表中仅包含几行,为小型表创建索引不太划算

--创建聚集索引,一个表中只能创建一个聚集索引.默认创建非聚集索引
create CLUSTERED index index_username
on t_money (username)
with fillfactor=60
go
--调用
select * from t_money with(INDEX=index_username)
 where username='judy'
--创建非聚集索引
create NoNCLUSTERED index index_money
on t_money ([money])
with fillfactor=60
go

--drop index t_money.index_userid
--创建唯一索引
create unique index index_userid
on t_money (userid)
with fillfactor=60
go


select * from t_money with(INDEX=index_username)
 where username='judy'
原文地址:https://www.cnblogs.com/zcttxs/p/3061347.html