数据库系统报告二(共16页).doc
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《数据库系统报告二(共16页).doc》由会员分享,可在线阅读,更多相关《数据库系统报告二(共16页).doc(16页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上数据库系统原理实验报告实验名称: 数据操作语言DML实验 任课教师: 霍纬纲 学 号: 姓 名: 黄帅 完成日期: 一、实验目的:1.建立基本表并进行DML操作。2.数据查询:单表查询、链接查询、嵌套查询、集合查询和统计。3.数据更新:增加、删除、查询和修改功能。二、实验步骤:1.进入Oracle的SQL*PLUS环境,输入:用户名:system 口令:manager 主机字符串:进入Oracle的SQL*PLUS环境,在此所创建的用户对象均属于system用户模式。2.在SQL*PLUS环境中用create insert语句创建基本表S、P、J和SPJ。S(SNO,
2、SNAME,STATUS,CITY)P(PNO,PNAME,COLOR,WEIGHT)J(JNO,JNAME,CITY)SPJ(SNO,PNO,JNO,QTY)create table S(SNO char(3) primary key,SNAME char(12),STATUS char(2),CITY char(10);create table P(PNO char(3) primary key,PNAME char(10),COLOR char(4),WEIGHT int);create table J(JNO char(3) primary key,JNAME char(12),CIT
3、Y char(10);create table SPJ(SNO char(3),PNO char(3),JNO char(3),QTY int,primary key (SNO,PNO,JNO),foreign key (SNO) references S (SNO),foreign key (PNO) references P (PNO),foreign key (JNO) references J (JNO);3、用Select语句对上述四个基本表进行如下查询(1)求供应工程J1零件的供应商号码SNO;select snofrom spjwhere jno=J1;(2)求供应工程J1零件P
4、1的供应商号码SNO;select snofrom spjwhere jno=J1and pno=P1;(3)求供应工程J1零件为红色的供应商号码SNO;select snofrom spj,pwhere jno=J1and p.pno=spj.pnoand color=红;(4)求没有使用天津供应商生产的红色零件的工程号JNO;select jnofrom jwhere not exists(select *from spjwhere spj.jno=j.jnoand sno in(select snofrom swhere city=天津)and pno in(select pnofrom
5、 pwhere color=红);(5)求至少用了供应商S1所供应的全部零件的工程号;select jnofrom spj spjzwhere not exists (select *from spj spjxwhere sno=S1and not exists(select *from spj spjywhere spjy.pno=spjx.pnoand spjy.jno=spjz.jno);(6)找出所有供应商的姓名和所在城市;select sname,cityfrom s;(7)找出所有零件的名称、颜色、重量;select pname,color,weightfrom p;(8)找出使用
6、供应商S1所供应零件的工程号;select jnofrom spjwhere sno=S1;(9)找出工程项目J2使用的各种零件的名称及其数量;select p.pname,spj.qtyfrom p,spjwhere p.pno=spj.pnoand spj.pno=J2;(10)找出上海厂商供应的所有零件号码;select pnofrom spjwhere sno in(select sno from swhere city=上海);(11)找出使用上号产的零件的工程名称;select jnamefrom j,spjwhere j.jno=spj.jnoand spj.sno in(sel
7、ect snofrom swhere city=上海);(12)找出没有使用天津产的零件的工程号码;select jnofrom jwhere not exists(select *from spj,s where spj.jno=j.jnoand spj.sno=s.snoand s.city=天津);(13)列出包含SNO,SNAME,PNO,PNAME,JNO,JNAME,QTY属性的清单;select sno,sname,pno,pname,jno,jname,qtyfrom s,p,j,spj;where spj.sno=s.snoand spj.jno=j.jnoand spj.p
8、no=p.pno;改:select s.sno,sname,p.pno,pname,j.jno,jname,qtyfrom s,p,j,spjwhere spj.sno=s.snoand spj.jno=j.jnoand spj.pno=p.pno;(14)统计各工程项目所用不同零件所用数量;select jno,sum(qty)from spj改:select jno,sum(qty)from spjgroup by jno(15)统计各供应商供应的各种零件数量;select sno,sum(qty)from spjgroup by sno4、用Insert、Delete、和Update语句
9、实现如下数据更新(1)将全部红色零件的颜色改为蓝色;update pset color=蓝where color=红;select *from p;(2)将工程J3的城市改为上海;update jset city=上海where j.jno=J3;select *from j;(3)由S5供给J4的零件P6改为由S3供应;update spjset sno=S3where sno=S5and jno=J4and pno=P6;select *from spj(4)从供应商关系中删除S2的元组,并从供应情况关系中删除相应元组;deletefrom spjwhere sno=S2;delete f
10、rom swhere sno=S2;select *from s;select *from spj;(5)、请将S2向工程项目J6供应200个P4零件的信息加入到供应关系; insert into s values(S2,发的,20,南京);insert into spj values(S2,P4,J6,200);select * from s;select *from spj; (6)、请将S6向项目J8供应500个P7零件的信息加入到供应关系; insert into s values(S6,如果,20,南极);insert into p values(P7,榔头,橙,15);insert
11、 into j values(J8,飞机厂,张贵庄);insert into spj values(S6,P7,J8,600);5、用Insert、Delete和Update语句实现如下数据更新create table Student(sno char(5) primary key,sname varchar(10) unique,ssex char(4) not null,sage number(3) default 0,sdept varchar(10);create table Course(cno char(5) primary key,cname varchar2(15) not n
12、ull,cpno char(5),ccredit number(4),foreign key (cpno) references Course(cno);create table SC(sno char(5),cno char(5),grade number(3),primary key (sno,cno),foreign key (sno) references Student(sno),foreign key (cno) references Course(cno);alter table Student add jiguan varchar2(20);alter table Studen
13、t add shijian date;alter table Course modify cno char(4);alter table Course modify cpno char(4);alter table SC modify cno char(4);alter table Student drop unique(sname);create unique index Stusname on Student(sname);create unique index Coucname on Course(cname);create index Sgrade on SC(sno asc,grad
14、e desc);insert into Student values(95001,李勇,男20,cs,北京,27-2月-05);insert into Student values(95002,张三,女,21,cs,天津,27-2月-05);insert into Student values(95003,李四,女,20,cs,上海,27-2月-05);insert into Student values(95004,王五,男,20,cs,海南,27-2月-05);insert into Student values(95005,赵六,男,21,cs,郑州,27-2月-05);insert i
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据库 系统 报告 16
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内