数据库原理实验报告 - 图文 联系客服

发布时间 : 星期二 文章数据库原理实验报告 - 图文更新完毕开始阅读80e8dc1a492fb4daa58da0116c175f0e7cd119ba

实验三 对象的建立与数据更新操作

一 实验要求

1 创建和修改对象 (1)创建表对象

按照下面的的结构与内容建两个关系。表名分别以S、T 开头,后面是建表人的学号(以下简记为T**、S** )。先用create table 命令建立表的初始结构,表T**的初始结构包括下面T**中前四个属性。然后再用alter table .add. 添加一个属性: QTY(库存量)。并插入相应的内容。

T** Title 计算机原理 C语言程序设计 数据库原理 计算机网络 Artificial intelligence Expert systems 软件工程 Fortran 程序设计 R.Ullman 鲁廷璋 顾学峰 H3067 S2005 S5006 17.00 35.00 18.00 370 200 180 author 张一平 李华 王家树 高明 P.Winston t_no S3092 price QTY 20.80 200 150 400 H1298 15.30 300 D1007 22.70 S5690 18.90 230 D2008 20.50 S**

T_no S3092 D1007 S5006 S5690

Page 304 280 315 300 17

pub-date 1986 1993 1987 1993

H1298 D2008 S2005 H3067 210 358 298 307 1989 1994 1995 1995 (2)用alter table.alter column.改变属性title 的长度。

(3)用子查询方式建新表。表名以ST 开头, 后面为建表人学号(简记为ST** )。 (新表内须包括title和price 两个属性。)

(4)按t_no 建索引,索引名为IT** (**表示建表人的学号,下同)。 (5)用子查询方式建视图,视图名为VT** , 并在视图上查找所需信息。 (6)删除以VT** 命名的视图。 (7)删除以ST** 命名的表。 2、记录的插入、删除与更新

(1)同前,用子查询方式建立表ST** 。该表的属性应有t_no, title, price。 (2)在ST** 表中插入一元组: S7028, Digital Image Processing, 36.00 (3)删除书名为“Fortran 程序设计”的那个元组。 (4)删除书号以H 开头的元组。 (5)把书价调整到原来价格的95% 。

(6)把书号以D 开头的那些书的书价减掉2.00元。 (7)将“计算机原理”的书号改为S1135。

(8)对所建的表,进行各种插入、删除、更新操作。

(9)每次修改表后,可用select 查看一下修改后表中的内容,看是否满足要求。 3、统计

(1)计算T** 表中这些书籍的最高书价、最低书价及平均书价。 (2)计算T** 表中的书的种类是多少。 (3)计算S** 表中1990年后出版的书有多少。 (4)计算总共有多少本书。

(5)对样例表,设计统计要求,获得各种统计量。

18

二 实验结果

/* 1 */ /*(1)*/

create database student use student

create table T631507020418( Title varchar(30), author varchar(15), t_no char(6),

price numeric(6,2) )

insert into T631507020418(Title,author,t_no,price) select '计算机原理','张一平','S3092','20.8' union all

select 'C语言程序设计','李华','H1298','15.3' union all

select '数据库原理','王家树','D1007','22.7' union all

select '计算机网络','高明','S5690','18.9' union all

select 'Artificial intelligence','P.Winston','D2008','20.5' union all

select 'Expert systems','R.Ullman','H3067','17' union all

select '软件工程','鲁廷璋','S2005','35' union all

select 'Fortran程序设计','顾学峰','S5006','18'

alter table T631507020418 add QTY int

update T631507020418 set QTY=200 where t_no='S3092' update T631507020418 set QTY=300 where t_no='H1298' update T631507020418 set QTY=150 where t_no='D1007' update T631507020418 set QTY=230 where t_no='S5690' update T631507020418 set QTY=400 where t_no='D2008' update T631507020418 set QTY=370 where t_no='H3067' update T631507020418 set QTY=200 where t_no='S2005' update T631507020418 set QTY=180 where t_no='S5006'

create table S631507020418(

19

T_no char(6), page int, pub_date date)

insert into S631507020418 select 'S3092','304','1986' union all

select 'D1007','280','1993' union all

select 'S5006','315','1987' union all

select 'S5690','300','1993' union all

select 'H1298','210','1989' union all

select 'D2008','358','1994' union all

select 'S2005','298','1995' union all

select 'H3067','307','1995'

/*(2)*/

alter table T631507020418

alter column Title varchar(35)

/*(3)*/

select Title,price into ST631507020418 from T631507020418

/*(4)*/

create index IT6315070200418 on T631507020418(t_no)

/*(5)*/

create view VT631507020418 as select * from T631507020418

/*(6)*/

drop view VT631507020418

/*(7)*/

drop table ST631507020418

20