-4
CREATE TABLE customer (
customer_id INT NOT NULL,
last_name VARCHAR(25) NOT NULL,
first_name VARCHAR(25) NOT NULL,
street_address VARCHAR(25) NOT NULL,
apt_number INT NULL,
city VARCHAR(20) NOT NULL,
state VARCHAR(2) NOT NULL,
zip_code INT NULL,
home_phone VARCHAR(12) NOT NULL,
mobile_phone VARCHAR(12) NULL,
other_phone VARCHAR(12) NULL,
PRIMARY KEY(customer_id)
);
CREATE TABLE donut_order(
donut_order_id INT NOT NULL,
customer_id INT NOT NULL,
order_date DATE NOT NULL,
special_handling_notes VARCHAR(255) NULL,
PRIMARY KEY(donut_order_id),
FOREIGN KEY (customer_id)
REFERENCES customer (customer_id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE donut_order_item (
donut_order_id INT NOT NULL,
donut_id INT NOT NULL,
qty INT NOT NULL,
PRIMARY KEY(donut_order_ID, donut_id),
UNIQUE INDEX(donut_id, donut_order_id),
CONSTRAINT donut_order FOREIGN KEY (donut_order_id)
REFERENCES donut_order (donut_order_id)
ON DELETE RESTRICT
ON UPDATE RESTRICT,
CONSTRAINT donut FOREIGN KEY (donut_id)
REFERENCES donut (donut_id)
ON DELETE RESTRICT
ON UPDATE RESTRICT
);
嗨,你可以編輯你的問題澄清 – Masterfego