本文为机械工业出版社 出版的《数据库系统基本教程(第三版)》一些课后习题的数据库操作命令。

#创建产品数据库
create database products;#使用产品数据库
use products;#创建产品表
create table Product(
maker char(5),
model int(10),
type char(10)
);#创建PC表
create table PC(
model int(10),
speed float,
ram int(7),
hd int(5),
price int(7)
);#创建Laptop表
create table Laptop(
model int(10),
speed float,
ram int(7),
hd int(5),
screen float,
price int(7)
);#创建printer表
create table Printer(
model int(10),
color char(10),
type char(15),
price int(7)
);#插入product数据
insert into Product (maker,model,type)
values
('A',1001,'pc'),
('A',1002,'pc'),
('A',1003,'pc'),
('A',2004,'laptop'),
('A',2005,'laptop'),
('A',2006,'laptop'),
('B',1004,'pc'),
('B',1005,'pc'),
('B',1006,'pc'),
('B',2007,'laptop'),
('C',1007,'pc'),
('D',1008,'pc'),
('D',1009,'pc'),
('D',1010,'pc'),
('D',3004,'printer'),
('D',3005,'printer'),
('E',1011,'pc'),
('E',1012,'pc'),
('E',1013,'pc'),
('E',2001,'laptop'),
('E',2002,'laptop'),
('E',2003,'laptop'),
('E',3001,'printer'),
('E',3002,'printer'),
('E',3003,'printer'),
('F',2008,'laptop'),
('F',2009,'laptop'),
('G',2010,'laptop'),
('H',3006,'printer'),
('H',3007,'printer');#插入PC表
insert into PC(model,speed,ram,hd,price)
values(1001,2.66,1024,250,2114),
(1002,2.10,512,250,955),
(1003,1.42,512,80,478),
(1004,2.80,1024,250,649),
(1005,3.20,512,250,630),
(1006,3.20,1024,320,1049),
(1007,2.20,1024,200,510),
(1008,2.20,2048,250,770),
(1009,2.00,1024,250,650),
(1010,2.80,2048,300,770),
(1011,1.86,2048,160,959),
(1012,2.80,1024,160,649),
(1013,3.06,512,80,529);#插入Laptop表
insert into Laptop
values
(2001,2.00,2048,240,20.1,3673),
(2002,1.73,1024,80,17.0,949),
(2003,1.80,512,60,15.4,549),
(2004,2.00,512,60,13.3,1150),
(2005,2.16,1024,120,17.0,2500),
(2006,2.00,2048,80,15.4,1700),
(2007,1.83,1024,120,13.3,1429),
(2008,1.60,1024,100,15.4,900),
(2009,1.60,512,80,14.1,680),
(2010,2.00,2048,160,15.4,2300);#插入Printer表
insert into Printer
values
(3001,'true','ink-jet',99),
(3002,'false','laser',239),
(3003,'true','laser',899),
(3004,'true','ink-jet',120),
(3005,'false','laser',120),
(3006,'true','ink-jet',100),
(3007,'true','laser',200);#查询速度大于3.00的pc型号
select model
from pc
where speed>=3.00;#查询能生产硬盘容量100GB以上的笔记本电脑的厂商
select distinct maker
from product
where
model in (
select distinct model
from Laptop
where hd>100);#查询厂商B生产的所有产品的型号和价格(select product.model,pc.price
from product,pc
where product.maker="B"and product.model=pc.model)union
(select product.model,laptop.price
from product,laptop
where product.maker="B" and product.model=laptop.model )union
(select product.model,printer.price
from product,printer
where product.maker="B"and product.model=printer.model);#查询所有彩色激光打印机的型号
select  model
from Printer
where color='true'and type='laser';#查询那些只售笔记本不售PC的厂商
select distinct product.maker
from product,laptop
where product.model=laptop.model and product.maker not in(
select product.maker
from product,pc
where product.model=pc.model);select distinct maker from product  where type="laptop"and maker not in
(select maker from product where type="pc");#查询在两种以上PC机中出现过的硬盘容量select hd
from pc
group by hd
having count(hd)>=2;#找出所有价格低于1000的个人计算机的型号、速度和硬盘的大小
select model ,speed,hd
from pc
where price>1000;#同上条,改名
select model ,speed as gigahertz,hd as gigabytes
from pc
where price>1000;#查找所有打印机制造商
select distinct maker
from Product
where type='printer';#价格高于1500的笔记本电脑型号、内存、屏幕尺寸
select model,ram,screen
from laptop
where price>=1500;#找出所有彩色打印机元祖
select *
from printer
where color='true';#找出速度为3.2且价格低于2000的个人计算机的型号和硬盘大小
select model,hd
from pc
where speed>=3.2 and price <=2000;#6.5.1 a)
#通过两条INSERT语句在数据库中添加如下信息:
#厂商C生产的型号为1100的pc,其速度为3.2,RAM容量大小为1024,硬盘容量为180,售价为2499
insert into product
values('C',1100,'PC');insert into pc
values(1100,3.2,1024,180,2499);#删除所有硬盘容量低于100GB的pc
delete from pc
where hd<100;///
#删除所有不生产打印机厂商生产的笔记本电脑
#第一步:删除laptop表
delete from laptop
where laptop.model in(
select product.model
from product
where maker not in(
select distinct maker
from product where type ='printer'
)
);#错误的方式删除product
delete from productwhere maker not in(select distinct makerfrom product where type ='printer'
);#第二步:通过中间表删除product中数据
delete from product
where maker not in(select a.maker from( select distinct a.maker from product a where a.type ='printer')a
);#厂商A收购了厂商B,将所有B生产的产品改为由A生产
update product
set maker='A'
where maker='B';#对于每台pc,将其RAM容量加倍,并将其硬盘容量增加60GB。
update pc
set ram=ram*2,hd=hd+60;#movie#建数据库
create database movie;#选择数据库
use  movie;#创建MovieStar
create table MovieStar(
name char primary key,
address char,
gender char,
birthdate date
);#创建MovieExec
create table MovieExec(
name char,
adress char,
cert int,
netWorth int,
primary key (name,cert)
);#创建表studio
create table studio(
name char,
address char,
presc int,
primary key(name)
);#8.1.1
#视图RichEXec给出了所有资产在10000000以上的制片人的名字、地址、证书号、资产create view RichExec as
select * from MovieExec
where networth>10000000;#视图StudioPress给出了既是电影公司经理(Studio president)
#又是制片人(Movie Executive)的那些人的名字,地址和证书号create view StudioPress as
select studio.name as name,studio.address as address ,presc
from movieExec,Studio
where Studio.name=movieexec.name;#视图ExecutiveStar给出了既是制片人又是演员的那些人的名字,地址,性别、生日,证书号和资产总值create view ExecutiveStar as
select MovieStar.name as name,MovieStar.address as address,gender,birthdate,cert,networth
from MovieStar,MovieExec
where MovieStar.name=MovieExec.name;#显示RichEXec表中元素名称
show columns from RichEXec;#显示StudioPress表中元素名称
show columns from StudioPress;#显示ExecutiveStar表中元素名称
show columns from ExecutiveStar;

数据库系统基础教程第三版 部分实验命令相关推荐

  1. python基础教程第三版电子版百度云-《python基础教程第三版》高清版PDF免费下载...

    下载地址1:http://t.cn/EGxO1sW Python基础教程 第3版Python简明教程书籍 Python编程从入门到实践 灵程序设计丛书 <python基础教程第三版>高清版 ...

  2. python程序实例教程基础-python基础教程第三版源代码

    [实例简介] python基础教程第三版源代码 python基础教程第三版源代码 [实例截图] [核心代码] Beginning_Python_version3_SourceCode └── Begi ...

  3. python基础教程第三版电子版-《python基础教程第三版》PDF高清完整版-免费下载...

    <python基础教程第3版>高清PDF下载地址:http://t.cn/EGxO1sW Python基础教程 第3版Python简明教程书籍 Python编程从入门到实践 灵程序设计丛书 ...

  4. python基础教程第三版-《Python基础教程第三版》原版中英文PDF+代码+袁国忠(译)...

    <Python基础教程第3版>整本书的结构安排还是比较明显的.先是基础知识和python的基本数据类型和语言特性介绍,然后是面向对象的编程.之后介绍python的标准库以及相关主题的编程( ...

  5. python基础教程pdf-python基础教程第三版.pdf

    您所在位置:网站首页 > 海量文档 &nbsp>&nbsp计算机&nbsp>&nbspPython python基础教程第三版.pdf689页 本文档 ...

  6. python基本代码教程-python基础教程第三版源代码

    [实例简介] python基础教程第三版源代码 python基础教程第三版源代码 [实例截图] [核心代码] Beginning_Python_version3_SourceCode └── Begi ...

  7. A First Course in Database Systems(数据库基础教程 第三版)课后答案——2.3.1\2.3.2\2.4.1

    A First Course in Database Systems(数据库基础教程 第三版)课后答案--2.3.1\2.3.2\2.4.1 文章目录 2.3.1 2.3.2 2.4.1 数据文件 2 ...

  8. python基础教程第三版豆瓣-1024,程序媛/猿请查收!

    点击上方蓝字关注我们 节专享福利:1024程序员 本期活动,不仅有赠书福利,且有购书福利,图灵公司联合当当网特意为{印象python}读者们申请了一波购书福利.感兴趣的读者朋友,请下拉至文末,领取福利 ...

  9. python基础教程免费下载-Python基础教程第三版PDF电子书免费下载

    <Python基础教程(第3版)>是2018年人民邮电出版社出版的图书,作者是[挪]Magnus Lie Hetland.该书全面介绍了Python的基础知识和基本概念,包括列表.元组.字 ...

最新文章

  1. 在建工程费用化处理_未确认融资费用和未实现融资收益的含义和区别
  2. 直面问题,咱谈焦虑、谈烦恼、谈如何成长
  3. R语言包_Matrix
  4. button 去掉原生边框
  5. java 怎么中断一个线程
  6. JSON学习笔记(一)- 语法
  7. 数据结构之二叉树:二叉查找树基本功能,Python代码实现——10
  8. Map与WeakMap
  9. 如何根据对象获取到对应的表名_Hands-on! 如何给 TiDB 添加新系统表
  10. int main(int argc,char *argv[])该函数中int argc和argv[]两个参数的理解你懂多少?
  11. Autoware 矢量地图标注(Autoware Maptool插件)
  12. yolo系列之yolo v3【深度解析】
  13. 基于RFM模型的Kmeans聚类算法实现
  14. frontend -- 框架
  15. error:‘%include‘ expects a file name
  16. 福州大学计算机专业排名2018,福州大学2019年排名第64位 较2018年下降3名
  17. 【论文解读】HIN2Vec: Explore Meta-paths in Heterogeneous Information Networks for Representation Learning
  18. 100个python算法超详细讲解:存钱
  19. 海思PQTool进行CCM调试经验
  20. 唐骏:我的成功可以复制

热门文章

  1. 服务器显示post是什么意思,post请求 post请求是什么
  2. 活体检测 Single-Side Domain Generalization for Face Anti-Spoofing 论文学习记录
  3. 为什么python性能差
  4. 企业员工电脑屏幕监控软件有免费版吗
  5. 减法公式运算法则_小学数学加减乘除计算运算法则
  6. SpringBoot拦截器失效问题excludePathPatterns失效问题
  7. 从校园到职场 - 再谈切忌照本宣科
  8. ... MWMCR::EvaluateFunction error ...
  9. 从小白到起飞的 RT-Thread 开发指南
  10. JavaScript 基础1入门、变量、运算符、表达式、进制