DatabaseProject/sqlCode
2024-04-16 20:49:39 +02:00

64 lines
1.6 KiB
Text

DROP TABLE IF EXISTS OrderSpec;
DROP TABLE IF EXISTS Recipe;
DROP TABLE IF EXISTS Ingredient;
DROP TABLE IF EXISTS Cookie;
DROP TABLE IF EXISTS Pallet;
DROP TABLE IF EXISTS Order;
DROP TABLE IF EXISTS Customer;
CREATE TABLE Customer (
customer_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
address VARCHAR(255)
);
CREATE TABLE Order (
order_id INT AUTO_INCREMENT PRIMARY KEY,
customer_id INT,
delivery_date DATE,
order_date DATE,
FOREIGN KEY (customer_id) REFERENCES Customer(customer_id)
);
CREATE TABLE Pallet (
pallet_id INT AUTO_INCREMENT PRIMARY KEY,
order_id INT,
manufacture_date DATE,
delivery_date DATE,
blocked BOOLEAN,
FOREIGN KEY (order_id) REFERENCES Order(order_id)
);
CREATE TABLE Cookie (
cookie_id INT AUTO_INCREMENT PRIMARY KEY,
pallet_id INT,
name VARCHAR(255),
FOREIGN KEY (pallet_id) REFERENCES Pallet(pallet_id)
);
CREATE TABLE OrderSpec (
order_id INT,
cookie_id INT,
quantity INT,
PRIMARY KEY (order_id, cookie_id),
FOREIGN KEY (order_id) REFERENCES Order(order_id),
FOREIGN KEY (cookie_id) REFERENCES Cookie(cookie_id)
);
CREATE TABLE Ingredient (
ingredient_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
stock INT,
unit VARCHAR(50),
delivery_date DATE,
delivery_amount INT
);
CREATE TABLE Recipe (
ingredient_id INT,
cookie_id INT,
amount FLOAT,
PRIMARY KEY (ingredient_id, cookie_id),
FOREIGN KEY (ingredient_id) REFERENCES Ingredient(ingredient_id),
FOREIGN KEY (cookie_id) REFERENCES Cookie(cookie_id)
);