数据库实验
(第三次)
题目1 实验内容:
1. 检索上海产的零件的工程名称;
2. 检索供应工程J1零件P1的供应商号SNO;
3. 检索供应工程J1零件为红色的供应商号SNO;
4. 检索没有使用天津生产的红色零件的工程号JNO;
5. 检索至少用了供应商S1所供应的全部零件的工程号JNO;
6. 检索购买了零件P1的工程项目号JNO及数量QTY,并要求对查询的结果按数量QTY降序排列。
1
select jname
from j
where jno in
(select jno
from spj
where sno in
(select sno
from s
where city ='上海'
)
);
2
select sno
from spj
where jno ='j1'and pno ='p1'
3
selectdistinct sno
from spj
where pno in
(select pno
from p
where color='红'and pno in
(select pno
from spj
where jno ='j1'
)
);
4
selectdistinct jno
from spj
where pno notin
(select pno
from p
where color ='红'and pno in
(select pno
from spj
where sno in
(select sno
from s
where city ='天津'
)
)
)
5
select jno
from spj
where sno ='s1'
6
select jno,qty
from spj
where pno ='p1'
orderby qty desc
四﹑思考题
如何提高数据查询和连接速度。
建立视图
2. 试比较连接查询和嵌套查询
有些嵌套查询是可以用连接来代替的,而且使用连接的方式,性能要比
嵌套查询高出很多
当查询涉及多个关系时,用嵌套查询逐步求解结构层次清楚,易于构造,具有结构化程序设计的优点。但是相比于连接运算,目前商用关系数据库管理系统对嵌套查询的优化做的还不够完善,所以在实际应用中,能够用连接运算表达的查询尽可能采用连接运算。
二
题目1实验内容:
把全部红色零件颜色改为粉红色;
由S1供给J1的零件P1今改为由S2供应,作必要修改;
删去全部蓝色零件及相应的SPJ记录;
把全部螺母的重量置为0;
为SPJ表的QTY字段设计CHECK约束:0〈 QTY〈1000;
实现对SPJ表的操作权限管理的使用。
1
update p
set COLOR = '粉红'
where pno in
(select pno
from P
where COLOR = '红')
2
update spj
set sno ='s2'
where sno ='s1'and pno ='p1'and jno ='j1'
3
delete
from spj
where pno ='p3'or pno ='p5'
delete
from p
where color ='蓝'
4
update p
set weight ='1'
where pname ='螺母'
5
alter table spj
add constraint c1 check(qty between 0 and 1000 )
create trigger spj_count
after INSERT ON spj
referencing
new table as delta
for each statement
insert into spjinsertlog(numbers)
select count(*)from delta
6
create role user1
grant select,update,delete,insert
on spj
to user1
数据库上机实验报告 来自淘豆网m.daumloan.com转载请标明出处.