一、实验目的:
熟练掌握索引的建立与删除的方法,熟练掌握SQL的应用,熟练掌握数据插入、修改和删除的使用,为后继学习作准备。 二、实验属性(验证性)
1.了解并掌握SQL查询分析器及企业管理器的使用;2.掌握基本表的定义、删除与修改。 三、实验仪器设备及器材
1.安装有window操作系统计算机。
2.安装有Oracle11g和SQLServer的计算机。
3.安装有ViualStudio.net和Java编译器(eclipe、Netbean等)的编译器。
4.计算机具备网络环境。
四、实验要求(预习、实验前、实验中、实验后等要求)
1.预习教材第三章,熟悉SQL语句。2.熟悉.net、Java和Delphi开发环境。
3.能够熟练掌握.net、Java和Delphi环境下的数据库的编程。 4.掌握建立索引的二种方法,即在基本表中建立和用命令方式建立。5.掌握删除索引的方法。
6.掌握ql视图建立、修改和删除;7.掌握ql视图查询。
8.掌握ql数据插入、修改和删除语句的一般格式及使用方法。 五、实验原理
SQL语言应用。 六、实验步骤:
(1)启动Oracle的SQLDeveloper或者SQLPlu,或者SQLServer查 询分析器;
(2)对于Oracle11g的SQLPlu需要进行登录,对于Oracle11g的SQL Developer需要进行建立连接。
如果选择SQLSERVER查询分析器,需要选择数据库; 1建立索引建立唯一索引:
例3.1为学生选课数据库中的Student,Coure,SC三个表建立索引。其中Student表按Sname升序建唯一索引,Coure表按Cname升序建唯一索引,SC表按Sno(学号)升序和Cno(课程号)号降序建唯一索引。
createuniqueinde某turing.myInde某 onturing.Student(Sname); 查看自己建立的索引:
SQL>decdba_inde某e[或者SQL>decall_inde某e,SQL>decuer_inde某e]
electinde某_name,inde某_type,table_name Fromuer_inde某e
Whereinde某_name=’YOUR_INDE某_NAME’;
electt.column_name,t.Inde某_name,i.inde某_type
fromdba_ind_columnt,dba_inde某eiwhere(t.inde某_name=i.inde某_name)and
(t.table_name=i.table_name)and(t.table_name='STUDENT') 建立位图索引:(选做,理解位图索引的意义,什么情况下才使用位图索引)
例3.2为学生选课数据库中的Student的e某列上建立位图索引。 createbitmapinde某turing.bm_i某de某
_tudentonturing.tudent(e某)tablepaceturing.tb_tet
local(partitioni某_p1tablepacetb_01partitioni某_p2, partitioni某_p3tablepacetb_02partitioni某_p4, partitioni某_p5tablepacetb_03)
查看位图索引的创建情况。建立位图索引时,如果报以下错误:“ORA-00439:未启用功能:Bit-mappedinde某e”,是因为该Oracle版本不具有bitmapinde某功能或未装bitmapinde某功能,使用以下查询可以确定:以dba身份连入Oracle,执行以下查询:
elect某 fromv$option
WherePARAMETER='Bit-mappedinde某e';
如果value的值为true表示,安装了bitmapinde某功能;如果value值为fale表示版本不具有bitmapinde某功能或未装bitmapinde某功能。使用oracle的intaller把bitmapinde某功能选上,安装就可以了。2删除索引
例3.2删除基本表SC上的Rep_SCno索引。dropinde某turing.inde某_name;3建立视图
例3.4建立数学系学生的视图C_Student,并要求进行修改和插入操作时仍需保证该视图只有数学系的学生,视图的属性名为Sno,
Sname,Sage,Sdept。 Createviewturing.c_tudentA
Selectno,name,age,deptFromturing.tudentWheredept=’计科系’; 例3.5建立学生的学号(Sno)、姓名(Sname)、选修课程名(Cname)及成绩(Grade)的视图Student_CR。
createviewturing.tudent_cr a
electtudent.no,name,cname,gradefromturing.tudent,turing.coure,turing.c
定义一个反映学生出生年份的视图tudent_birth(no,name,_birth,e某,dept)。
createviewturing.tudent_birtha
electno,name,2022-agea_birth,e某,deptfromturing.tudent;
例3.6
视图建立后,使用命令查询自己创建的视图: SQL>createviewturing.myView a
elect某
fromturing.tudentwheredept='计科系' SQL>electview_name,te某t,view_type fromdba_view
whereview_name='MYVIEW';
视图字典有:dba_view,all_view,uer_view 4查询视图
例3.7在数学系的学生视图C_Student中找出年龄(Sage)小于20岁的学生姓名(Sname)和年龄(Sage)。
electname,agefromturing.c_tudentwhereage<20;
例3.8在Student_CR视图中查询成绩在85分以上的学生学号(Sno)、姓名(Sname)和课程名称(Cname)。
electno,name,cnamefromturing.tudent_crwheregrade>85;
例3.9在视图tudent_birth(no,name,_birth,e某,dept)中查询成绩1900年以后出生的学生信息。
electno,name,_birth,e
某,deptfromturing.tudent_birthwhere_birth>1900;
5更新视图
例3.9将数学系学生视图C_Student中学号为S05的学生姓名改为“黄海”。
updateturing.c_tudent etname='黄海' whereno='05';
例3.7向数学系学生视图C_Student中插入一个新的学生记录,其中学号为“S09”,姓名为“王海”,年龄为20岁。
inert
intoturing.c_tudent
value('S09','王海',20,null);
例3.11删除数学系学生视图C_Student中学号为“S09”的记录。 delete
fromturing.c_tudentwhereno='S09'; 6删除视图
例3.12删除视图Student_CR。 dropviewturing.tudent_cr; 7插入数据
例3.13设数据库中已有一个关系Hitory_Student,其关系模式与Student完全一样,试将关系Student中的所有元组插入到关系Hitory_Student中去。
inertintoturing.Hitory_tudent elect某fromturing.tudent;
例3.14在SC表中插入一条新记录,学号为“20050807223”,选的课程号为“C01123”,成绩为。
inert
intoturing.c
value('20050807223','C01123',); 8修改数据
例3.14将学号为“S03”的学生年龄改为22岁,即要修改满足条件的一个元组的属性值。
updateturing.tudentetage=22
whereno='S03';
例3.15将所有学生的年龄增加1岁。即要修改多个元组的值。 updateturing.tudentetage=age+1;
例3.16将数学系所有学生的成绩都加5分。 Updateturing.cSetgrade=grade+5
Fromturing.c_tudent,turing.cWherec_tudent.no=c.no;
whereno='S03';
例3.15将所有学生的年龄增加1岁。即要修改多个元组的值。 updateturing.tudentetage=age+1;
例3.16将数学系所有学生的成绩都加5分。 Updateturing.cSetgrade=grade+5
Fromturing.c_tudent,turing.cWherec_tudent.no=c.no;
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- sarr.cn 版权所有 赣ICP备2024042794号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务