if (exists (select * from sys.indexes where name = 'idx_stu_name')) drop index student.idx_stu_namegocreate index idx_stu_nameonstudent(name); --联合索引if (exists (select * from sys.indexes where name = 'idx_uqe_clu_stu_name_age')) drop index student.idx_uqe_clu_stu_name_agegocreate unique clustered index idx_uqe_clu_stu_name_ageon student(name, age); if (exists (select * from sys.indexes where name = 'idx_cid')) drop index student.idx_cidgo if (exists (select * from sys.indexes where name = 'idx_cid')) drop index student.idx_cidgo --非聚集索引create nonclustered index idx_cidonstudent (cid)with fillFactor = 30; --填充因子 --聚集索引if (exists (select * from sys.indexes where name = 'idx_sex')) drop index student.idx_sexgocreate clustered index idx_sexonstudent(sex); --聚集索引if (exists (select * from sys.indexes where name = 'idx_name')) drop index student.idx_namegocreate unique index idx_nameonstudent(name);
--创建视图if (exists (select * from sys.objects where name = 'v_stu')) drop view v_stugocreate view v_stuasselect id, name, age, sex from student;
4、 修改视图
alter view v_stuasselect id, name, sex from student; alter view v_stu(编号, 名称, 性别)as select id, name, sex from studentgoselect * from v_stu; select * from information_schema.views;
5、 加密视图
--加密视图if (exists (select * from sys.objects where name = 'v_student_info')) drop view v_student_infogocreate view v_student_infowith encryption --加密as select id, name, age from studentgo--view_definition is nullselect * from information_schema.views where table_name like 'v_stu';