MySQL上机试题 联系客服

发布时间 : 星期一 文章MySQL上机试题更新完毕开始阅读70ad4bfce53a580217fcfe2b

MySQL上机试题

1. 2.

创建数据库,名称为考生的学号;(10分)

创建数据表customer(客户)、deposite(存款)、bank(银行),表结构如下:(10分) customer的表结构 属性名称 c_id name location salary bank的表结构 属性名称 b_id bank_name 类型与长度 char(5) char(30) 中文含义 银行标识 银行名次 主键,非空 非空 备注 类型与长度 char(6) varchar(30) Varchar(30) decimal(8,2) 中文含义 客户标识 客户姓名 工作地点 工资 主键,非空 非空 备注 deposite的表结构 属性名称 d_id c_id b_id dep _date dep_type amount 3.

类型与长度 int char(6) char(5) date enum(1,3,5) decimal(8,2) 中文含义 存款流水号 主键,非空,自增 客户标识 银行标识 存入日期 存款期限 存款金额 外键,关联customer表的c_id 外键,关联bank表的b_id 枚举型,1,3,5分别代表1年期、3年期和5年期 备注 录入数据如下:(10分)

customer的数据如下,注意最后一条记录用你的学号和你的姓名代替 c_id 101001 101002 101003 101004 你的学号

name 孙杨 郭海 卢江 郭惠 你的姓名 location 广州 南京 苏州 济南 北京 salary 1234 3526 6892 3492 6324 bank的数据如下: b_id B0001 B0002 B0003 B0004 bank_name 工商银行 建设银行 中国银行 农业银行 deposite的数据如下: d_id 1 2 3 4 5 6 7 8 9 10 11 12 4.

c_id 101001 101002 101003 101004 101001 101002 101003 101004 101001 101002 101003 101004 b_id B0001 B0003 B0002 B0004 B0003 B0001 B0004 B0002 B0002 B0004 B0003 B0001 dep_date 2011-04-05 2012-07-15 2010-11-24 2008-03-31 2002-02-07 2004-09-23 2003-12-14 2007-04-21 2011-02-11 2012-05-13 2001-01-24 2009-08-23 dep_type 3 5 1 1 3 3 5 5 1 1 5 3 amount 42526 66500 42366 62362 56346 353626 36236 26267 435456 234626 26243 45671 创建存储过程update_salary,更新customer表的salary属性,将salary低于5000的客户的salary变为原来的2倍. (10分)

5. 6.

创建视图bank_total,对deposite表进行统计,按银行统计存款总数,显示为b_id,total. (10分) 创建视图show_deposite,对deposite、customer、bank进行查询,查询条件为location在广州、苏州、济南的客户,存款在300000至500000之间的存款记录,显示客户姓名name、银行名称bank_name、存款金额amount. (10分)

7. 8.

为customer的name创建普通索引,名称为idx_name.(10分) 新建表dep_log,数据结构如下:(5分)

属性名称 id d_id b_id operation tsp 类型与长度 int int char(5) varchar(30) timestamp 中文含义 流水号 主键,非空,自增 备注 存款流水号 银行标识 操作 时间戳 (1) 创建一个触发器名称为insert_trigger, 在deposite插入记录时在dep_log中插入一条记录,将操

作operation值为INSERT,并记录银行标识b_id;(5分)

(2) 在deposite中插入一条记录,客户标识c_id为你的学号,银行标识b_id为B0003,存款日期

dep_date为当前系统日期,存款期限type为3,存款金额amount为50000,以验证触发器是否有效。(5分)

9.

完成以下题目:

(1) 在bank中插入一条新记录B0005,交通银行;(5分)

(2) 创建存储过程copydata,将deposite表存款流水号d_id未在dep_log中记录的农业银行B0004

的全部存款记录逐一复制到新建的交通银行,客户标识c_id不变,银行标识为B0005,存款期限type、存款金额amount不变,存款日期为当前系统日期。并将操作记录写入dep_log表,包括农业银行的存款流水号,银行标识B0004,操作operation为COPY,以避免重复操作。(10分)