数据库SQL实验报告书.docx
- 文档编号:512115
- 上传时间:2023-04-29
- 格式:DOCX
- 页数:19
- 大小:394.77KB
数据库SQL实验报告书.docx
《数据库SQL实验报告书.docx》由会员分享,可在线阅读,更多相关《数据库SQL实验报告书.docx(19页珍藏版)》请在冰点文库上搜索。
南京理工大学紫金学院实验报告书
课程名称:
《数据库系统》
实验题目:
实验1
用SQL语句创建数据库和表班级:
计算机科学与技术2班学号:
09061257
姓 名:
朱书宏
指导教师:
叶庆生
成
绩:
批阅教师:
年
月
日
《数据库系统》实验报告090601257朱书宏-9-
一、实验目的
1.使用SQL2005练习使用SQL语句创建数据库与表2.练习SQL查询、修改、删除等语句语句
3.掌握数据库中创建表时主键、约束条件的纂写
二.实验内容
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给出的数据库模式和数据写出后面的查询语句以及查询结果。
Classes(class,type,country,numCuns,bore,displacement)Ships(name,class,launched)
Battles(name,date)
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上调试语句并运行结果
四、实验结果
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)
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(
modelvarchar(16)primarykey,speedvarchar(16)notnull,ramvarchar(16)notnull,
hdvarchar(16)notnull,screemvarchar(16)notnull,priceintnotnull,
)
createtableprinter(
modelvarchar(16)primarykey,colorvarchar(16)notnull,typevarchar(16)notnull,priceintnotnull,
)
2.根据下列数据库模式,用SQL语句创建一个适当地数据库,并创建相关的表,注意表中的主键和外键及某些属性域的约束。
Classes(class,type,country,numCuns,bore,displacement)Ships(name,class,launched)
Battles(name,date)
Outcomes(ship,battle,result)
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,
)
3.将相关的数据用SQL语句插入到数据中。
SQL语句:
数据库1:
zuoye1
insert
intoProduct(marker,model,type)values('A',1001,'pc');
insert
intoProduct(marker,model,type)values('A',1002,'pc');
insert
intoProduct(marker,model,type)values('A',1003,'pc');
insert
intoProduct(marker,model,type)values('A',2004,'laptop');insert
intoProduct(marker,model,type)values('A',2005,'laptop');insert
intoProduct(marker,model,type)values('A',2006,'laptop');insert
intoProduct(marker,model,type)values('B',1004,'pc');
insert
intoProduct(marker,model,type)values('B',1005,'pc');
insert
intoProduct(marker,model,type)values('B',1006,'pc');
insert
intoProduct(marker,model,type)values('B',2007,'laptop');insert
intoProduct(marker,model,type)values('C',1007,'pc');
insert
intoProduct(marker,model,type)values('D',1008,'pc');
insert
intoProduct(marker,model,type)values('D',1009,'pc');
insert
intoProduct(marker,model,type)values('D',1010,'pc');
insert
intoProduct(marker,model,type)values('D',3004,'printer');
insert
intoProduct(marker,model,type)values('D',3005,'printer');insert
intoProduct(marker,model,type)values('E',1011,'pc');
insert
intoProduct(marker,model,type)values('E',1012,'pc');
insert
intoProduct(marker,model,type)values('E',1013,'pc');
insert
intoProduct(marker,model,type)values('E',2001,'laptop');insert
intoProduct(marker,model,type)values('E',2002,'laptop');insert
intoProduct(marker,model,type)values('E',2003,'laptop');insert
intoProduct(marker,model,type)values('E',3001,'printer');insert
intoProduct(marker,model,type)values('E',3002,'printer');insert
intoProduct(marker,model,type)values('E',3003,'printer');insert
intoProduct(marker,model,type)values('F',2008,'laptop');insert
intoProduct(marker,model,type)values('F',2009,'laptop');insert
intoProduct(marker,model,type)values('G',2010,'laptop');insert
intoProduct(marker,model,type)values('H',3006,'printer');insert
intoProduct(marker,model,type)values('H',3007,'printer');insert
intoPC(model,speed,ram,hd,price)values(1001,2.66,1024,250,2114);
insert
intoPC(model,speed,ram,hd,price)values(1002,2.10,512,250,995);
insert
intoPC(model,speed,ram,hd,price)values(1003,1.42,512,80,478);
insert
intoPC(model,speed,ram,hd,price)values(1004,2.80,1024,250,649);
insert
intoPC(model,speed,ram,hd,price)values(1005,3.20,512,250,630);
insert
intoPC(model,speed,ram,hd,price)values(1006,3.20,1024,320,1049);
insert
intoPC(model,speed,ram,hd,price)values(1007,2.20,1024,200,510);
insert
intoPC(model,speed,ram,hd,price)values(1008,2.20,2048,250,770);
insert
intoPC(model,speed,ram,hd,price)values(1009,2.00,1024,250,650);
insert
intoPC(model,speed,ram,hd,price)values(1010,2.80,2048,300,770);
insert
intoPC(model,speed,ram,hd,price)values(1011,1.86,2048,160,959);
insert
intoPC(model,speed,ram,hd,price)values(1012,2.80,1024,160,649);
insert
intoPC(model,speed,ram,hd,price)values(1013,3.06,512,80,529);
insert
intoPrinter(model,color,type,price)values(3001,'true','ink-jet',99);insert
intoPrinter(model,color,type,price)values(3002,'false','laser',239);insert
intoPrinter(model,color,type,price)
values(3003,'true','laser',899);insert
intoPrinter(model,color,type,price)values(3004,'true','ink-jet',120);insert
intoPrinter(model,color,type,price)values(3005,'false','laser',120);insert
intoPrinter(model,color,type,price)values(3006,'true','ink-jet',100);insert
intoPrinter(model,color,type,price)values(3007,'true','laser',200);insert
intoLaptop(model,speed,ram,hd,screen,price)values(2001,2.00,2048,240,20.1,3673);
insert
intoLaptop(model,speed,ram,hd,screen,price)values(2002,1.73,1024,80,17.0,3673);
insert
intoLaptop(model,speed,ram,hd,screen,price)values(2003,1.802,512,60,16.4,549);
insert
intoLaptop(model,speed,ram,hd,screen,price)values(2004,2.00,512,60,13.3,1150);
insert
intoLaptop(model,speed,ram,hd,screen,price)values(2005,2.16,1024,120,17.0,2600);
insert
intoLaptop(model,speed,ram,hd,screen,price)values(2006,2.00,2048,80,15.4,1700);
insert
intoLaptop(model,speed,ram,hd,screen,price)values(2007,1.83,1024,120,13.3,1429);
insert
intoLaptop(model,speed,ram,hd,screen,price)values(2008,1.60,1024,100,15.4,900);
insert
intoLaptop(model,speed,ram,hd,screen,price)values(2009,1.60,512,80,14.1,680);
insert
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);
insert
intoClasses(class,type,country,numGuns,bore,displacement)values('Iowa','bb','USA',9,15,46000);
insert
intoClasses(class,type,country,numGuns,bore,displacement)values('Kongo','bc','Janpan',8,14,32000);
insert
intoClasses(class,type,country,numGuns,bore,displacement)values('NorthCarolina','bb','USA',9,16,37000);
insert
intoClasses(class,type,country,numGuns,bore,displacement)values('Renown','bc','Gt.Brintain',6,15,32000);
insert
intoClasses(class,type,country,numGuns,bore,displacement)values('Revenge','bb','Gt.Brintain',8,15,29000);
insert
intoClasses(class,type,country,numGuns,bore,displacement)values('Tennessee','bb','USA',12,14,32000);
insert
intoClasses(class,type,country,numGuns,bore,displacement)values('Yamato','bb','Janpan',9,18,65000);
insert
intoBattles(name,date)values('DenmarkStrait','5/24-27-41');insert
intoBattles(name,date)values('Guadalcanal','11/15/42');insert
intoBattles(name,date)values('NorthCape','12/26/43');insert
intoBattles(name,date)values('SurigaoStrait','10/25/44');insert
intoShips(name,class,launched)values('California','Tennessee',1921);insert
intoShips(name,class,launched)values('Haruna','Kongo',1915);insert
intoShips(name,class,launched)values('Hiei','Kongo',1914);insert
intoShips(name,class,launched)
values('Iowa','Iowa',1943);insert
intoShips(name,class,launched)values('Kirishima','Kongo',1915);insert
intoShips(name,class,launched)values('Kongo','Kongo',1913);insert
intoShips(name,class,launched)values('Missouri','Iowa',1944);insert
intoShips(name,class,launched)values('Mnsashi','Yamato',1942);insert
intoShips(name,class,launched)values('NewJersey','Iowa',1943);insert
intoShips(name,class,launched)
values('NorthCalifornia','NorthCalifornia',1941);insert
intoShips(name,class,launched)values('Ramilliss',
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据库 SQL 实验 报告书