http://download.csdn.net/detail/fuchunyuan0/9573203此链接可以下载我上传的word文档sql案例原题,为北风网mysql学习部分的考试题.
create database if not exists CustomDB;
创建表,代码如下:
答:
/*创建顾客表*/
create table if not exists customer(
c_id char(6) primary key,
name varchar(30)not null,
location varchar(30),
salary decimal(8,2)
);
/*创建银行表*/
create table if not exists bank(
b_id char(5) primary key,
bank_name char(30) not null
);
/*创建存款表(注意外键的代码使用)*/
create table if not exists deposite(
d_id int(10) auto_increment primary key,
c_id char(6),
b_id char(5),
dep_date date,
amount decimal(8,2),
constraint FK_c_id foreign key(c_id) references customer(c_id)
);
/*插入数据*/
insert into customer
values('101001','孙杨','广州',1234),
('101002','郭海','南京',3526),
('101003','卢江','苏州',6892),
('101004','郭惠','济南',3492);
insert into bank
values('B0001','工商银行'),
('B0002','建设银行'),
('B0003','中国银行');
insert into bank
values('B0004','农业银行');
insert into deposite
values(1,'101001','B0001','2011-04-05',42526),
(2,'101002','B0003','2012-07-15',66500),
(3,'101003','B0002','2010-11-24',42366),
(4,'101004','B0004','2008-03-31',62362),
(5,'101001','B0003','2002-02-07',56346),
(6,'101002','B0001','2004-09-23',353626),
(7,'101003','B0004','2003-12-14',36236),
(8,'101004','B0002','2007-04-21',26267),
(9,'101001','B0002','2011-02-11',435456),
(10,'101002','B0004','2012-05-13',234626),
(11,'101003','B0003','2001-01-24',26243),
(12,'101004','B0001','2009-08-23',45671);
update deposite set amount =amount+10000
where c_id in(select c_id from custom where name='孙杨');
update deposite set amount=amount+1000
where dep_date='2011-04-05' and b_id in(select b_id from bank where bank_name='工商银行');
update deposite set b_id=(select b_id from bank where bank_name='建设银行')
where c_id in(select c_id from customer where name='郭海');
select customer.c_id,name,bank_name,amount
from inner join customer on customer.c_id=deposite.c_id
inner join bank on bank.b_id=deposite.b_id
where name='郭海' and bank_name='工商银行';
查询日期为2011-04-05这一天进行过存款的客户ID,客户姓名,银行名称,存款金额
查询郭海在工商银行的存款信息(显示信息:客户ID,客户姓名,银行标识,银行名称,存款日期,存款金额)