数据库SQL实验报告书Word下载.docx
- 文档编号:683397
- 上传时间:2023-04-29
- 格式:DOCX
- 页数:19
- 大小:394.77KB
数据库SQL实验报告书Word下载.docx
《数据库SQL实验报告书Word下载.docx》由会员分享,可在线阅读,更多相关《数据库SQL实验报告书Word下载.docx(19页珍藏版)》请在冰点文库上搜索。
二.实验内容
1.根据下列数据库模式,用SQL语句创建一个适当地数据库,并创建相关的表,注意表中的主键和外键及某些属性域的约束。
Product(marker,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(name,date)
Outcomes(ship,battle,result)
3.将相关的数据用SQL语句插入到数据中。
4.基于习题5.2.4给出的数据库模式和数据写出后面的查询语句以及查询结果。
Outcomes(ship,battle,result)a)找出战舰类型的数量。
b)找出不同类型战舰拥有的平均火炮数量。
!
c)找出战舰的平均火炮数量。
注意c)和b)的不同在于:
在计算均值的时候,是使用战舰的数目还是战舰的类型数目。
d)找出每一类型(class)的第一艘船下水的年份。
e)找出每一类型中被击沉船的数目。
f)找出至少有3艘船的类型中被击沉的船的数目。
g)军舰火炮使用的炮弹的重量(以磅为单位)大约是火炮的口径(以英寸为单位)的一半。
找出各个国家的军舰炮弹重量的平均值。
5.根据习题5.2.1给出的数据库模式,写出下面的数据库修改。
描述对该习题数据库修改够的结果。
Product(marker,model,type)
PC(model,speed,ram,hd,rd,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)删除所有不制造打印机的厂商生产的手提电脑。
e)厂商A收购了厂商B,将所有B生产的产品改为由A生产。
f)对于每台PC,把它的内存加倍并且增加20G的硬盘容量。
(记住UPDATE语句中可以同时更改多个属性的值)
g)把厂商B生产的手提电脑的屏幕尺寸增加一英寸并且价格下调$100。
三、实验步骤
1.创建数据库表
2.编写SQL语句
3,在SQL2005上调试语句并运行结果
四、实验结果
SQL语句:
createdatabase[zuoye1]createtableproduct
(
markervarchar(16)primarykey,modelvarchar(16)notnull,typevarchar(16)notnull,
)
createtablePC(
modelvarchar(16)primarykey,speedvarchar(16)notnull,ramvarchar(16)notnull,
hdvarchar(16)notnull,rdvarchar(16)notnull,priceintnotnull
createtablelaptop(
hdvarchar(16)notnull,screemvarchar(16)notnull,priceintnotnull,
createtableprinter(
modelvarchar(16)primarykey,colorvarchar(16)notnull,typevarchar(16)notnull,priceintnotnull,
SQL语句:
createdatabase[zuoye2]createtableClasses
classvarchar(16)primarykeynotnull,typevarchar(16)notnull,
countryvarchar(16)notnull,numGunsint,
boreint,displacementint,
createtableShips(
namevarchar(16)primarykey,classvarchar(16)notnull,launchedvarchar(16)notnull,
createtableBattles(
namevarchar(16)primarykey,datevarchar(16)notnull,
createtableOutcomes(
shipvarchar(16)primarykey,battlevarchar(16)notnull,resultvarchar(16)notnull,
数据库1:
zuoye1
insert
intoProduct(marker,model,type)values('
A'
1001,'
pc'
);
1002,'
1003,'
2004,'
laptop'
insert
2005,'
2006,'
B'
1004,'
1005,'
1006,'
2007,'
C'
1007,'
D'
1008,'
1009,'
1010,'
3004,'
printer'
3005,'
E'
1011,'
1012,'
1013,'
2001,'
2002,'
2003,'
3001,'
3002,'
3003,'
F'
2008,'
2009,'
G'
2010,'
H'
3006,'
3007,'
intoPC(model,speed,ram,hd,price)values(1001,2.66,1024,250,2114);
intoPC(model,speed,ram,hd,price)values(1002,2.10,512,250,995);
intoPC(model,speed,ram,hd,price)values(1003,1.42,512,80,478);
intoPC(model,speed,ram,hd,price)values(1004,2.80,1024,250,649);
intoPC(model,speed,ram,hd,price)values(1005,3.20,512,250,630);
intoPC(model,speed,ram,hd,price)values(1006,3.20,1024,320,1049);
intoPC(model,speed,ram,hd,price)values(1007,2.20,1024,200,510);
intoPC(model,speed,ram,hd,price)values(1008,2.20,2048,250,770);
intoPC(model,speed,ram,hd,price)values(1009,2.00,1024,250,650);
intoPC(model,speed,ram,hd,price)values(1010,2.80,2048,300,770);
intoPC(model,speed,ram,hd,price)values(1011,1.86,2048,160,959);
intoPC(model,speed,ram,hd,price)values(1012,2.80,1024,160,649);
intoPC(model,speed,ram,hd,price)values(1013,3.06,512,80,529);
intoPrinter(model,color,type,price)values(3001,'
true'
'
ink-jet'
99);
intoPrinter(model,color,type,price)values(3002,'
false'
laser'
239);
intoPrinter(model,color,type,price)
values(3003,'
899);
intoPrinter(model,color,type,price)values(3004,'
120);
intoPrinter(model,color,type,price)values(3005,'
intoPrinter(model,color,type,price)values(3006,'
100);
intoPrinter(model,color,type,price)values(3007,'
200);
intoLaptop(model,speed,ram,hd,screen,price)values(2001,2.00,2048,240,20.1,3673);
intoLaptop(model,speed,ram,hd,screen,price)values(2002,1.73,1024,80,17.0,3673);
intoLaptop(model,speed,ram,hd,screen,price)values(2003,1.802,512,60,16.4,549);
intoLaptop(model,speed,ram,hd,screen,price)values(2004,2.00,512,60,13.3,1150);
intoLaptop(model,speed,ram,hd,screen,price)values(2005,2.16,1024,120,17.0,2600);
intoLaptop(model,speed,ram,hd,screen,price)values(2006,2.00,2048,80,15.4,1700);
intoLaptop(model,speed,ram,hd,screen,price)values(2007,1.83,1024,120,13.3,1429);
intoLaptop(model,speed,ram,hd,screen,price)values(2008,1.60,1024,100,15.4,900);
intoLaptop(model,speed,ram,hd,screen,price)values(2009,1.60,512,80,14.1,680);
intoLaptop(model,speed,ram,hd,screen,price)values(2010,2.00,2048,160,15.4,2300);
数据库2:
zuoye2
intoClasses(class,type,country,numGuns,bore,displacement)values('
Bismark'
bb'
Germany'
8,15,42000);
Iowa'
USA'
9,15,46000);
Kongo'
bc'
Janpan'
8,14,32000);
NorthCarolina'
9,16,37000);
Renown'
Gt.Brintain'
6,15,32000);
Revenge'
8,15,29000);
Tennessee'
12,14,32000);
Yamato'
9,18,65000);
intoBattles(name,date)values('
DenmarkStrait'
5/24-27-41'
Guadalcanal'
11/15/42'
NorthCape'
12/26/43'
SurigaoStrait'
10/25/44'
intoShips(name,class,launched)values('
California'
1921);
Haruna'
1915);
Hiei'
1914);
intoShips(name,class,launched)
values('
1943);
Kirishima'
1913);
Missouri'
1944);
Mnsashi'
1942);
NewJersey'
NorthCalifornia'
1941);
Ramilliss'
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据库 SQL 实验 报告书