第3章 SQL 习题 - 3.4

本文针对一个保险公司数据库,提供了三个SQL查询示例:统计2009年发生事故的驾驶员人数,新增事故记录,以及删除指定人员拥有的特定车型。通过具体操作演示了如何验证查询和操作的效果,确保数据的准确更新。
摘要由CSDN通过智能技术生成

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(
    
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值