数据库实验报告(实验二)
- 格式:doc
- 大小:112.00 KB
- 文档页数:9
沈阳工程学院
学生实验报告(课程名称:数据库原理及应用)
实验题目:数据库中数据的更新
班级学号姓名
日期地点指导教师
一、实验目的
掌握SQL的数据更新功能,包括:插入数据、修改数据和删除数据.
二、实验环境
Oracle10g数据库系统.
三、实验内容与要求
对实验一中的三个表student,course,sc进行更新操作.
(1)在student表中输入6条记录.
(2)在course 表中输入4条记录.
(3)在sc表中输入10条记录,注意有些课程可有多人选,有些课程可能没人选.
(4)练习数据的删除和修改.
(5)练习多个记录的增加,删除和修改.
四、实验过程及结果分析
(1)在student表中输入6条记录.
(1)在student表中输入6条记录.
insert
Into student
V alues ('1’,’石金栋’,’男’,20,’IS’);
insert
Into student(sno,sname,ssex,sage,sdept)
V alues ('2','赵振飞','男',21,'IS');
insert
Into student(sno,sname,ssex,sage,sdept)
V alues ('3','李杰','男',20,'cS');
insert
Into student(sno,sname,ssex,sage,sdept)
V alues ('4','王雨萌','男',20,'Eg');
insert
Into student(sno,sname,ssex,sage,sdept)
V alues ('5','姚立东','男',20,'Sx');
insert
Into student(sno,sname,ssex,sage,sdept)
V alues ('6','罗连翩','男',20,'IS');
ERROR at line 3:
ORA-00911: invalid character
分析:标点符号应为英文的.
改正:insert
Into student(sno,sname,ssex,sage,sdept)
V alues ('1','石金栋','男',20,'IS');
实验结果如图1.1所示
图1.1
(2)在course表中输入4条记录.
Insert Into course V alues('1','cs',4);
Insert Into course V alues('2','Is',3);
Insert Into course V alues('3','Eg',4);
Insert Into course V alues('1','Sx',6);
ERROR at line 1:
ORA-00001: unique constraint (RJB11216.SYS_C006305) violated
分析:课程号要唯一
改正:Insert Into course V alues('4','Sx',6);
实验结果如图1.2所示
图1.2
(3)在sc表中输入10条记录,注意有些课程可有多人选,有些课程可能没人选.
Insert Into sc V alues ('1','1',80);
Insert Into sc V alues ('1','2',96);
Insert Into sc V alues ('2','3',NULL);
Insert Into sc V alues ('3','4',77);
Insert Into sc V alues ('3','1',66);
Insert Into sc V alues ('4','1',null);
Insert Into sc V alues ('4','4',86);
Insert Into sc V alues ('5','3',90);
Insert Into sc V alues ('6','2',70);
Insert Into sc V alues ('6','5',78);
ERROR at line 1:
ORA-02291: integrity constraint (RJB11216.SYS_C006314) violated - parent key not found
分析:外码必须与所关联的表的主码相一致,course表中找不到cno=5.
改正:Insert Into sc V alues ('6','1',78);
实验结果如图1.3所示
图1.3
(4)练习数据的删除与修改.
修改:Update student
Set sdept ='Cs'
Where sno='3';
实验结果如图1.4所示
图1.4
删除:delete
From student
Where sno='1';
实验结果如图1.5所示
图1.5 (5)练习多个数据的增加,删除与修改
删除:delete
From sc
Where grade=78;
delete
From sc
Where grade=86;
实验结果如图1.6所示
图1.6
增加:insert
Into student(sno,sname,ssex,sage,sdept)
V alues ('1','石金栋','男',20,'IS');
insert
Into course(cno,cname,ccredit)
V alues ('5','Dl',20);
实验结果如图1.7和1.8所示
图1.7
图1.8
修改:Update student Set sage =19 Where sno='1';
Update student Set sage =24 Where sno='2';
Update student Set sage =22 Where sno='3'; 实验结果如图1.9所示
图1.9
五、成绩评定
优良中及格不及格出勤
格式
内容
分析
总评
指导教师:
年月日。