教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 小学教育 >

山东大学 数据库 实验四 复制表

来源:网络收集 时间:2026-09-07
导读: Test4 复制表、修改表结构、修改数据(2学时) 一、 实验内容 利用oracle管理平台完成对表的结构、数据进行修改,每一个问题可以通过多个SQL语句完成。 二、 实验题目 1. 将pub用户下表student_41及数据复制到主用户的表test4_01中,使用alter table语句为表

Test4 复制表、修改表结构、修改数据(2学时)

一、 实验内容

利用oracle管理平台完成对表的结构、数据进行修改,每一个问题可以通过多个SQL语句完成。

二、 实验题目

1. 将pub用户下表student_41及数据复制到主用户的表test4_01中,使用alter table语句为表增加五个列:“总成绩:sum_score”、 “平均成绩:avg_score”(四舍五入到个位)、“总学分:sum_credit”、“院系编号:did varchar(2) ”。

使用update语句,利用pub.student_course、pub.course,统计 “总成绩”; create table test4_01 as select* from pub.student_41

alter table test4_01 add sum_score int

alter table test4_01 add avg_score numeric(5,1)

alter table test4_01 add sum_credit int

alter table test4_01 add did varchar(2)

select *from test4_01

create table test01 as select sid,sum(score) sum_score from pub.student_course group by sid

update test4_01

set sum_score=(select test01.sum_score

from test01

where test01.sid=test4_01.sid)

2. 将pub用户下表student_41及数据复制到主用户的表test4_02中,使用alter table语句为表增加五个列:“总成绩:sum_score”、 “平均成绩:avg_score”(四舍五入到个位)、“总学分:sum_credit”、“院系编号:did varchar(2) ”。

利用pub.student_course、pub.course,统计“平均成绩”;

create table test4_02 as select* from pub.student_41

alter table test4_02 add sum_score int

alter table test4_02 add avg_score numeric(5,1)

alter table test4_02 add sum_credit int

alter table test4_02 add did varchar(2)

select *from test4_02

create table test02 as select sid,avg(score) avg_score from pub.student_course group by sid update test4_02

set avg_score=(select test02.avg_score

from test02

where test02.sid=test4_02.sid)

3. 将pub用户下表student_41及数据复制到主用户的表test4_03中,使用alter table

语句为表增加五个列:“总成绩:sum_score”、 “平均成绩:avg_score”(四舍五入到个位)、“总学分:sum_credit”、“院系编号:did varchar(2) ”。

使用update语句,利用pub.student_course、pub.course,统计 “总学分”; drop table test4_03

create table test4_03 as select* from pub.student_41

alter table test4_03 add sum_score int

alter table test4_03 add avg_score numeric(5,1)

alter table test4_03 add sum_credit int

alter table test4_03 add did varchar(2)

select *from pub.course

drop table test03

create table test031 as select sid,cid,score from pub.student_course

alter table test031 add credit int

update test031

set credit=(select credit

from pub.course

where test031.cid=pub.course.cid and score>=60)

update test031

set credit=0

where score<60

create table test03 as select sid,sum(credit) sum_credit from test031

group by sid

update test4_03

set sum_credit=(select test03.sum_credit

from test03

where test03.sid=test4_03.sid)

4. 将pub用户下表student_41及数据复制到主用户的表test4_04中,使用alter table

语句为表增加五个列:“总成绩:sum_score”、 “平均成绩:avg_score”(四舍五入到个位)、“总学分:sum_credit”、“院系编号:did varchar(2) ”。

根据院系名称到pub.department或者pub.department_41中,找到对应编号,填写到院系编号中,如果都没有对应的院系,则填写为00。

drop table test4_04

drop table test04

create table test4_04 as select* from pub.student_41

alter table test4_04 add sum_score int

alter table test4_04 add avg_score numeric(5,1)

alter table test4_04 add sum_credit int

alter table test4_04 add did varchar(2)

select *from pub.department

create table test04 as select* from pub.department

insert into test04 select*from pub.department_41

update test4_04

set did=(select test04.did

from test04

where test4_04.dname=test04.dname)

where dname in(select dname from test04)

update test4_04

set did='00'

where dname not in(select dname from test04) or dname is null

update dbtest set test=4

select * from dbscore

5. 将pub用户下表student_41及数据复制到主用户的表test4_05中,使用alter table

语句为表增加五个列:“总成绩:sum_score”、 “平均成绩:avg_score”(四舍五入到个位)、“总学分:sum_credit”、“院系编号:did varchar(2) ”。

(1) 利用pub.student_course、pub.course,统计 “总成绩”;

(2) 利用pub.student_course、pub.course,统计“平均成绩”;

(3) 利用pub.student_course、pub.course,统计 “总学分”;

(4) 根据院系名称到pub.department或者pub.department_41中,找到对应编号,

填写到院系编号中,如果都没有对应的院系,则填写为00。

create table test4_05 as select* from pub.student_41

alter table test4_05 add sum_score int

alter table test4_05 add avg_score numeric(5,1)

alter table test4_05 add sum_credit int

alter table test4_05 add did varchar(2)

update test4_05

set sum_score=(select test4_01.sum_score

from test4_01

where test4_01.sid=test4_05.sid)

update test4_05

set avg_score=(select test4_02.avg_score

from test4_02

where test4_02.sid=test4_05.sid)

update test4_05

set sum_credit=(select test4_03.sum_credit

from test4_03

where test4_03.sid=test4_05.sid)

update test4_05

set did=(select test04.did

from test04

where test04.dname=test4_05.dname)

where dname in (select dname

from test04)

update test4_05

set did='00'

where dname not in (select dname

from test04) or dname is null

update dbtest set test=4

select * from dbscore

6. 将pub用户下的Student_42及数据复制到主用户的表test4_06中,对表中的数据进

行整理,修复那些不规范的数据:

剔除姓名列中的所有空格;

select *from pub.student_42

drop table test4_06

create table test4_06 as select* from pub.student_42

update test4_06

set name=replace(name,' ','')

7. 将pub用户下的Student_42及数据复制到主用户的表test4_07中,对表中的数 …… 此处隐藏:4135字,全部文档内容请下载后查看。喜欢就下载吧 ……

山东大学 数据库 实验四 复制表.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/43381.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)