1、sql脚本:
(红色为修改的脚本)
create database if not exists insurance ;
use insurance;
create table if not exists person(
driver_id varchar(10),
name varchar(30),
address varchar(50),
primary key(driver_id)
);
create table if not exists car (
license varchar(30),
model varchar(30),
year smallint,
primary key(license)
);
create table if not exists
accident(
report_number varchar(10) primary key,
date date,
location varchar(50)
);
create table if not exists
owns(
driver_id varchar(10),
license varchar(30),
primary key(driver_id,license),
foreign key(driver_id) references person(driver_id),
foreign key(license) references car(license)
);
create table if not exists
xukezheng(
driver_id varchar(10),
che varchar(10),
report_number varchar(10),
demage_amount smallint,
primary key(driver_id,che,report_number),
foreign key(driver_id) references person(driver_id),
foreign key(report_number) references accident(report_number)
);
2、错误:
在执行sql语句是,无法创建xukezheng这个表。
3、错误原因:
在xukezheng表中,引用了report_number当作外键,而这个外键在accident中没有被定义为主键。出现错误。