3.13
Write SQL DDL corresponding to the schema in Figure 3.17. Make any reasonable assumptions about data types, and be sure to declare primary and foreign keys.
CREATE TABLE person (
VARCHAR(15),
driver_id VARCHAR(30) NOT NULL,
name VARCHAR(40),
address PRIMARY KEY (driver_id)
);
CREATE TABLE car (
VARCHAR(8),
license_plate VARCHAR(7),
model year NUMERIC(4,0) CHECK (year > 1701 AND year < 2100),
PRIMARY KEY (license_plate)
);
CREATE TABLE accident (
VARCHAR(10),
report_number year NUMERIC(4,0) CHECK (year > 1701 AND year < 2100),
VARCHAR(30),
location PRIMARY KEY (report_number)
);
CREATE TABLE owns (
VARCHAR(15),
driver_id VARCHAR(8),
license_plate PRIMARY KEY (driver_id, license_plate),
FOREIGN KEY (driver_id) REFERENCES person(driver_id)
ON DELETE CASCADE,
FOREIGN KEY (license_plate) REFERENCES car(license_plate)
ON DELETE CASCADE
);
CREATE TABLE participated (
VARCHAR(10),
report_number VARCHAR(8),
license_plate VARCHAR(15),
driver_id NUMERIC(10,2),
damage_amount PRIMARY KEY(report_number, license_plate),
FOREIGN KEY (report_number) REFERENCES accident(report_number),
FOREIGN KEY (license_plate) REFERENCES car(license_plate)
);