3.4考虑图3-18中的保险公司数据库,其中加下划线的是主码。为这个关系数据库构造出如下SQL查询:
person(driver_id, name, address)
car(licence, model, year)
accident(report_number, date, location)
owns(driver_id, license)
participated(report_number, license, driver_id, damage_amount)
为了更好的验证答案是否正确,我们创建一个数据库insurance,添加几个表,并且增加一些数据。
drop table person cascade;
drop table car cascade;
drop table accident cascade;
drop table owns cascade;
drop table participated cascade;
-- 司机信息
create table person(
driver_id int not null, -- 驾驶证号
name varchar(20) not null, --姓名
address varchar(30) not null, --住址
primary key (driver_id)
);
--车辆信息
create table car(
licence int not null, -- 行驶证号
model varchar(20), --车辆型号
year numeric(4, 0) check (year > 1970 and year < 2100), --生产日期
primary key(licence)
);
--事故信息
create table accident(