文档详情

数据库考试题答案.doc

发布:2016-12-24约7.29千字共9页下载文档
文本预览下载声明
测验 题目选择: 学号最后1位 试题 1,2 第一套 3,4 第二套 5,6 第三套 7,8 第四套 9,0 第五套 二、要求 1、完成题目后将sql语句帖在对应题目下方。 2、所有完成后将word文件保存为 “班级-学号后两位-姓名”方式:如“12-03-XXX” 三、提示 1、注意完成每一个小题后立即贴在word文档中。 2、只能在本机上提交,不能在1个机器上提交多份。 3、如有雷同试卷,都取消成绩。 数据库 附加company数据库,共有五张表,结构如下。按照要求完成以下各题。 (1)/*员工人事表employee */ emp_no char(5) Not null primary key 员工编号 emp_name char(10) Not null 员工姓名 sex char(1) Not null 性别 dept char(4) Not null 所属部门 title char(6) Not null 职称 date_hired datetime Not null 到职日 birthday datetime Null 生日 salary int Not null 薪水 addr char(50) null 住址 (2)/*客户表customer */ cust_id char(5) Not null primary key 客户号 cust_name char(20) Not null, 客户名称 addr char(40) Not null, 客户住址 tel_no char(10) Not null, 客户电话 zip char(6) null 邮政编码 (3)/*销售主表sales */ order_no int Not null primary key 订单编号 cust_id char(5) Not null, 客户号 sale_id char(5) Not null, 业务员编号 tot_amt numeric(9,2) Not null, 订单金额 order_date datetime Not null, 订货日期 ship_date datetime Not null, 出货日期 invoice_no char(10) Not null 发票号码 (4)/*销货明细表sale_item */ order_no int Not null, primary key 订单编号 prod_id char(5) Not null, primary key 产品编号 qty int Not null 销售数量 unit_price numeric(7,2) Not null 单价 order_date datetime null 订单日期 (5)/*产品名称表product */ pro_id char(5) Not null primary key 产品编号 prod_name char(20) Not null 产品名称 第一套 一、必做题 计算出sale_item表中每一笔销售数据的销售金额,并按照销售金额的大小排序。 select order_no ,Qty*Unit_price as 销售金额 from sale_item order by 销售金额 检索product 表和sale_item表中数量大于的相同产品的产品编号、产品名称、数量、单价。 select pro_id,prod_name,Qty,Unit_price from product,sale_item where Qty2 and product.pro_id=sale_item.Prod_id; 找出目前业绩未超过50000元的员工。(要求用嵌套查询) Select emp_no, emp_name, sex, employee.dept,.title,employee.date_hired, employee.birthday,employee.salary,employee.addr from employee,sales where employee.emp_no=sales.sale_id and tot_amt500000 设置sales 表和sale_item的外键关系为“层叠”。修改sales表中发票号码为I000000004的订单,将其发票号码改为I000000054,其订货明细数据也一并修改。 alter table sales add constraint FK_sales foreign key(order_no) references sale_item(order_n
显示全部
相似文档