1、南京理工大学紫金学院实验报告书课程名称: 数据库系统实验题目: 实验 1 用 SQL 语句创建数据库和表 班 级: 计算机科学与技术 2 班学 号: 09061257姓名: 朱书宏指导教师: 叶庆生成绩:批阅教师:年月日数据库系统实验报告 090601257 朱书宏 - 9 -一、实验目的1. 使用 SQL2005 练习使用 SQL 语句创建数据库与表2练习 SQL 查询、修改、删除等语句语句3.掌握数据库中创建表时主键、约束条件的纂写二 .实验内容1. 根据下列数据库模式,用 SQL 语句创建一个适当地数据库,并创建相关的表,注意表中的主键和外键及某些属性域的约束。Product(marke
2、r, model, type) PC(model, speed, ram, hd, rd, price)Laptop(model, speed, ram ,hd, screen, price) Printer(model, color, type, price)2. 根据下列数据库模式,用 SQL 语句创建一个适当地数据库,并创建相关的表,注意表中的主键和外键及某些属性域的约束。Classes ( class , type , country , numCuns , bore , displacement ) Ships( name , class , launched )Battles( n
3、ame , date )Outcomes ( ship , battle , result )3. 将相关的数据用 SQL 语句插入到数据中。4. 基于习题 5.2.4 给出的数据库模式和数据写出后面的查询语句以及查询结果。Classes ( class , type , country , numCuns , bore , displacement ) Ships( name , class , launched )Battles( name , date )Outcomes ( ship , battle , result ) a)找出战舰类型的数量。b)找出不同类型战舰拥有的平均火炮数量
4、。!c)找出战舰的平均火炮数量。注意 c)和 b)的不同在于:在计算均值的时候,是使用战舰的数目还是战舰的类型数目。!d)找出每一类型( class )的第一艘船下水的年份。!e)找出每一类型中被击沉船的数目。!f) 找出至少有 3 艘船的类型中被击沉的船的数目。!g)军舰火炮使用的炮弹的重量(以磅为单位)大约是火炮的口径(以英寸为单位)的一半。 找出各个国家的军舰炮弹重量的平均值。5. 根据习题 5.2.1 给出的数据库模式,写出下面的数据库修改。描述对该习题数据库修改够的结果。 Product(marker, model, type)PC(model, speed, ram, hd, rd
5、, price) Laptop(model, speed, ram ,hd, screen, price) Printer(model, color, type, price)a) 通过两条 INSERT 语句在数据库中添加如下信息:制造商 C 生产的型号为 1100 的 PC,速度为 1800,RAM 为 256,硬盘大小 80,具有一个 20x 的 DVD,售价为$2499。!b) 加入如下信息:对于数据库中每台 PC,都对应一台与其速度、RAM、硬盘相同,具有 15 英寸的屏幕,型号大于 1100、价格高于$500 的相同厂商制造的手提电脑。c) 删除所有硬盘不超过 20G 的 PC。d
6、) 删除所有不制造打印机的厂商生产的手提电脑。e) 厂商 A 收购了厂商 B,将所有 B 生产的产品改为由 A 生产。f) 对于每台 PC,把它的内存加倍并且增加 20G 的硬盘容量。(记住 UPDATE 语句中可以同时更改多个属性的值)!g) 把厂商 B 生产的手提电脑的屏幕尺寸增加一英寸并且价格下调$100。三、实验步骤1. 创建数据库 表2. 编写 SQL 语句3,在 SQL2005 上调试语句并运行结果四、实验结果1. 根据下列数据库模式,用 SQL 语句创建一个适当地数据库,并创建相关的表,注意表中的主键和外键及某些属性域的约束。Product(marker, model, type
7、) PC(model, speed, ram, hd, rd, price)Laptop(model, speed, ram ,hd, screen, price) Printer(model, color, type, price)SQL语句:create database zuoye1 create table product(marker varchar(16) primary key, model varchar(16) not null, type varchar(16) not null,)create table PC (model varchar(16) primary key
8、, speed varchar(16) not null, ram varchar(16) not null,hd varchar(16) not null, rd varchar(16) not null, price int not null)create table laptop (model varchar(16) primary key, speed varchar(16) not null, ram varchar(16) not null,hd varchar(16) not null, screem varchar(16) not null, price int not nul
9、l,)create table printer (model varchar(16) primary key, color varchar(16) not null, type varchar(16) not null, price int not null,)2. 根据下列数据库模式,用 SQL 语句创建一个适当地数据库,并创建相关的表,注意表中的主键和外键及某些属性域的约束。Classes ( class , type , country , numCuns , bore , displacement ) Ships( name , class , launched )Battles( n
10、ame , date )Outcomes ( ship , battle , result )SQL 语句:create database zuoye2 create table Classes(class varchar(16)primary key not null, type varchar(16) not null,country varchar(16) not null, numGuns int,bore int, displacement int,)create table Ships (name varchar(16) primary key, class varchar(16)
11、 not null, launched varchar(16) not null,)create table Battles (name varchar(16) primary key, date varchar(16) not null,)create table Outcomes (ship varchar(16) primary key, battle varchar(16) not null, result varchar(16) not null,)3. 将相关的数据用 SQL 语句插入到数据中。SQL 语句:数据库 1:zuoye1insertinto Product (marke
12、r,model,type) values(A,1001,pc);insertinto Product (marker,model,type) values(A,1002,pc);insertinto Product (marker,model,type) values(A,1003,pc);insertinto Product (marker,model,type) values(A,2004,laptop); insertinto Product (marker,model,type) values(A,2005,laptop); insertinto Product (marker,mod
13、el,type) values(A,2006,laptop); insertinto Product (marker,model,type) values(B,1004,pc);insertinto Product (marker,model,type) values(B,1005,pc);insertinto Product (marker,model,type) values(B,1006,pc);insertinto Product (marker,model,type) values(B,2007,laptop); insertinto Product (marker,model,ty
14、pe) values(C,1007,pc);insertinto Product (marker,model,type) values(D,1008,pc);insertinto Product (marker,model,type) values(D,1009,pc);insertinto Product (marker,model,type) values(D,1010,pc);insertinto Product (marker,model,type) values(D,3004,printer);insertinto Product (marker,model,type) values
15、(D,3005,printer); insertinto Product (marker,model,type) values(E,1011,pc);insertinto Product (marker,model,type) values(E,1012,pc);insertinto Product (marker,model,type) values(E,1013,pc);insertinto Product (marker,model,type) values(E,2001,laptop); insertinto Product (marker,model,type) values(E,2002,laptop); insertinto Product (marker,model,type) values(E,2003,laptop); insert