MYSQL视图和索引

 

 

 

 

 

#第7章
#【例7.1】在stusys数据库中创建V_StudentScore视图,包括学号、姓名、性别、专业、课程号、成绩,且专业为计算机。
use stusys;
create view v_StudentScore
    as
    select a.sno as 学号,
    a.sname as 姓名,
    a.ssex as 性别,
    a.speciality as 专业,
    b.cno as 课程号,
    b.grade as 成绩
    from student a,score b
    where a.speciality='计算机' and a.sno=b.sno;
    select * from v_StudentScore;

    
#【例7.2】在stusys数据库中创建V_StudentCourseScore视图,包括学号、姓名、性别、课程名、成绩,按学号升序排列,且专业为计算机。
use stusys;
create view v_StudentScore
as
select a.sno,a.sname,a.ssex,b.cname,c.grade
from student a,course b,score c
where a.sno=c.sno and b.cno=c.cno and speciality='计算机'
order by a.sno;
#【例7.3】 分别查询V_StudentScore视图、V_StudentCourseScore视图。


#【例7.4】 查询计算机专业学生的学号、姓名、性别、课程名。

#【例7.5】在stusys数据库中,以student为基表,创建专业为通信的可更新视图
create or replace view V_StudentSpecialityComm
as
select *
from student
where speciality ='通信';
#【例7.6】 向V_StudentSpecialityComm视图中插入一条记录:('196006','程超','男','1998-04-28','通信', 50)。 
use stusys;
insert into V_StudentSpecialityComm
values('196006','程超','男','1998-04-28','通信',50);
select * from student;


#【例7.7】 将V_StudentSpecialityComm视图中学号为196006的学生的总学分增加2分。
update V_StudentSpecialityComm set tc=tc+2
where sno = '196006';
select * from student;
#【例7.8】 删除V_StudentSpecialityComm视图中学号为196006的记录。
use stusys;
delete from V_StudentSpecialityComm
where sno='196006'
#【例7.9】 将例7.1定义的视图V_StudentScore视图进行修改,取消专业为计算机的要求。

#【例7.10】修改例7.2创建的视图V_StudentCourseScore,学号以降序排列。 

#【例7.11】 在stusys数据库中,将视图V_StudentCourseScore删除。
 
#【例7.12】 在stusys数据库中student表的sname列上,创建一个普通索引I_studentSname。
use stusys;
create index i_studentSname on student(sname);
#【例7.13】 在stusys数据库中course表的cno列上,创建一个索引I_courseCno,要求按课程号cno字段值前2个字符降序排列。

#【例7.14】 在stusys数据库中student表的tc列(降序)和sname列(升序),创建一个组合索引I_studentTcSname。

#【例7.15】在stusys数据库teacher表的tname列,创建一个唯一性索引I_teacherTname,并按降序排列。

#【例7.16】在stusys数据库中,创建新表score1表,主键为sno和cno,同时在grade列上创建普通索引。


#【例7.17】查看例7.16所创建的score1表的索引。


#【例7.18】删除已建索引I_studentTcSname。


#【例7.19】删除已建索引I_teacherTname。


#课本P41——3设计性实验

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值