附答案数据库期中考试复习题目汇总.docx

上传人:b****0 文档编号:353775 上传时间:2022-10-09 格式:DOCX 页数:20 大小:96.24KB
下载 相关 举报
附答案数据库期中考试复习题目汇总.docx_第1页
第1页 / 共20页
附答案数据库期中考试复习题目汇总.docx_第2页
第2页 / 共20页
附答案数据库期中考试复习题目汇总.docx_第3页
第3页 / 共20页
附答案数据库期中考试复习题目汇总.docx_第4页
第4页 / 共20页
附答案数据库期中考试复习题目汇总.docx_第5页
第5页 / 共20页
点击查看更多>>
下载资源
资源描述

附答案数据库期中考试复习题目汇总.docx

《附答案数据库期中考试复习题目汇总.docx》由会员分享,可在线阅读,更多相关《附答案数据库期中考试复习题目汇总.docx(20页珍藏版)》请在冰豆网上搜索。

附答案数据库期中考试复习题目汇总.docx

附答案数据库期中考试复习题目汇总

《数据库概论》课程期中复习题目汇总

一、为某百货公司设计一个E-R模型。

  百货管辖若干个连锁商店,每家商店经营若干商品,每家商店有若干职工,但每个职工只能服务于一家商店。

  实体类型“商店”的属性有:

商店编号,店号,店址,店经理。

实体类型“商品”的属性有:

商品编号,商品名,单价,产地。

实体类型“职工”的属性有:

职工编号,职工名,性别,工资。

在联系中应反映出职工参加某商店工作的开始时间,商店销售商品的有销售量。

  试画出反映商店、商品、职工实体类型及联系类型的ER图,并将其转换成关系模式集。

二、关系代数

设有三个关系:

S(S#,SNAME,AGE,SEX)

SC(S#,C#,GRADE)

C(C#,CNAME,TEACHER)

说明:

S#——学号SNAME——学生姓名AGE——年龄SEX——性别

           C#——课程号CNAME——课程名TEACHER——教师 GRADE——成绩

试用关系代数写出查询语句。

(1)检索LIU老师所授课程的课程号、课程名。

 

(2)检索年龄大于23岁的男学生的学号与姓名。

 

(3)检索学号为S3学生所学课程的课程名与任课教师名。

 

(4)检索至少选修LIU老师所授课程中一门课程的女学生的姓名。

(5)检索WANG同学不学的课程号。

 

(6)检索至少选修两门课程的学生学号。

 

(7)检索全部学生都选修的课程的课程号与学生学号。

 

(8)检索选修课程包含LIU老师所授课程的学生学号。

(用∞代表自然连接):

(1)πC#,CNAME(σTEACHER='LIU'(C))

(2)πS#,SNAME(σAGE>'23'∧SEX='男'(S))

(3)πCNAME,TEACHER(σS#='S3'(SC∞C))

(4)πSNAME(σSEX='女'∧TEACHER='LIU'(S∞SC∞C))

(5)πC#(C)-πC#(σSNAME='WANG'(S∞SC))

(6)πS#(σ1=4∧2≠5(SC×SC))(SC自乘之后,同一个学号下两个课程号不同的元组)

(7)πC#,S#(SC∞(πS#,C#(SC)÷πS#(S))))

(8)πS#(σTEACHER='LIU'(S∞SC∞C))

三、SQL语句

(1)

1、建立一个数据库和五张表的表结构。

(1)/*员工人事表employee*/

emp_no

char(5)

Notnull

primarykey

员工编号

emp_name

char(10)

Notnull

员工姓名

sex

char

(1)

Notnull

性别

dept

char(4)

Notnull

所属部门

title

char(6)

Notnull

职称

date_hired

datetime

Notnull

到职日

birthday

datetime

Null

生日

salary

int

Notnull

薪水

addr

char(50)

null

住址

Mod_date

datetime

Default(getdate())

操作者

(2)/*客户表customer*/

cust_id

char(5)

Notnull

primarykey

客户号

cust_name

char(20)

Notnull,

客户名称

addr

char(40)

Notnull,

客户住址

tel_no

char(10)

Notnull,

客户电话

zip

char(6)

null

邮政编码

(3)/*销售主表sales*/

order_no

int

Notnull

primarykey

订单编号

cust_id

char(5)

Notnull,

客户号

sale_id

char(5)

Notnull,

业务员编号

tot_amt

numeric(9,2)

Notnull,

订单金额

order_date

datetime

Notnull,

订货日期

ship_date

datetime

Notnull,

出货日期

invoice_no

char(10)

Notnull

发票号码

(4)/*销货明细表sale_item*/

order_no

int

Notnull,

primarykey

订单编号

prod_id

char(5)

Notnull,

产品编号

qty

int

Notnull

销售数量

unit_price

numeric(7,2)

Notnull

单价

order_date

datetime

null

订单日期

(5)/*产品名称表product*/

prod_id

char(5)

Notnull

primarykey

产品编号

prod_name

char(20)

Notnull

产品名称

4、通过T-SQL语句修改表约束。

1)分别为每张表建立主键约束。

2)为相关表建立外键约束。

3)在表employee加入CHECK约束:

输入的员工编号必须以E开头的5位数编号,性别只能为M/F。

4)为销售主表sales中的发票编号字段建立UNIQUE约束。

5)创建一个视图,该视图只含上海客户信息,即客户号、客户姓名、住址

6)对视图添加一条记录数据(注意:

分别查看customer表和该视图的结果)

7)删除视图中所有姓“王”的客户数据

8)通过视图修改表内某一客户的姓名

9)有两个基本表employee和sales,创建一个视图,该视图包含相同业务员的编号、姓名、订单号、销售总金额

10)将上述视图中订单号为10001的记录的销售总金额改为60000

11)给上述视图添加一条记录数据

12)删除上述视图

(1)建立数据库jianghong

createdatabasejianghong

on

(name='jianghong',

'E:

\数据库\jianghong.mdf',

size=3,

maxsize=10,

1)

logon

(name='jianghonglog',

'E:

\数据库\jianghonglog.ldf',

size=1,

maxsize=5,

go

(2)建立数据表

①创建employee表:

createtableemployee

(emp_nochar(5)notnullprimarykey,

emp_namechar(10)notnull,

sexchar

(1)notnull,

deptchar(4)notnull,

titlechar(6)notnull,

data_hireddatetimenotnull,

birthdaydatetimenull,

salaryintnotnull,

addrchar(50)null,

Mod_datedatetimeDefault(getdate()),)

②创建customer表:

createtablecustomer

(cust_idchar(5)notnullprimarykey,

cust_namechar(20)notnull,

addrchar(40)notnull,

tel_nochar(10)notnull,

zipchar(6)null,)

③创建sales表:

createtablesales

(order_nointnotnullprimarykey,

cust_idchar(5)notnull,

sale_idchar(5)notnull,

tot_amtnumeric(9,2)notnull,

order_datedatetimenotnull,

ship_datedatetimenotnull,

invoice_nochar(10)notnull,)

④创建sale_item表:

createtablesale_item

(order_nointnotnull,

prod_idchar(5)notnull,

qtyintnotnull,

unit_pricenumeric(7,2)notnull,

order_datedatetimenull,

primarykey(order_no,prod_id),)

⑤创建product表:

createtableproduct

(prod_idchar(5)notnullprimarykey,

prod_namechar(20)notnull,)

(3)为相关表建立外键约束

①altertablesalesaddforeignkey(cust_id)referencescustomer(cust_id);

②altertablesale_itemaddforeignkey(order_no)referencessales(order_no);

③altertablesale_itemaddforeignkey(prod_id)referencesproduct(prod_id);

(4)为表employee加入check约束:

altertableemployeeaddconstraintc1check(emp_nolike'E____'and(sex='M'orsex='f'));

(5)为表sales发票号建立unique约束:

altertablesalesaddunique(invoice_no);

(6)创建一个视图,该视图只含上海客户信息,即客户号、客户姓名、住址:

createviewsh_kehu

as

selectcust_id,cust_name,addr

fromcustomer

whereaddrlike'上海'

2

(7)删除视图中所有姓“王”的客户数据:

DELETE

FROMsh_kehu

WHEREcust_nameLIKE'王%'

(8)通过视图修改表内某一客户的姓名

updatesh_kehu

setcust_name='江洪好'

wherecust_id='4224'

(9)有两个基本表employee和sales,创建一个视图,该视图包含相同业务员的编号、姓名、订单号、销售总金额:

createviewem_sa

as

selectsale_id,emp_name,order_no,tot_amt

fromemployee,sales

whereemployee.emp_no=sales.sale_id

(10)将上述视图中订单号为10001的记录的销售总金额改为60000:

updateem_sa

settot_amt='60000'

whereorder_no=10001

(11)删除上述视图:

dropviewem_sa

dro

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1