DatabaseProject/sqlCode

63 lines
1.6 KiB
Text
Raw Normal View History

2024-04-16 20:49:39 +02:00
DROP TABLE IF EXISTS OrderSpec;
DROP TABLE IF EXISTS Recipe;
DROP TABLE IF EXISTS Ingredient;
DROP TABLE IF EXISTS Pallet;
2024-04-17 23:19:16 +02:00
DROP TABLE IF EXISTS Cookie;
DROP TABLE IF EXISTS Orders;
2024-04-16 20:49:39 +02:00
DROP TABLE IF EXISTS Customer;
CREATE TABLE Customer (
customer_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
address VARCHAR(255)
);
CREATE TABLE Orders (
2024-04-16 20:49:39 +02:00
order_id INT AUTO_INCREMENT PRIMARY KEY,
customer_id INT,
delivery_date DATE,
order_date DATE,
FOREIGN KEY (customer_id) REFERENCES Customer(customer_id)
);
2024-04-17 23:19:16 +02:00
CREATE TABLE Cookie (
name VARCHAR(255) PRIMARY KEY
);
2024-04-16 20:49:39 +02:00
CREATE TABLE Pallet (
pallet_id INT AUTO_INCREMENT PRIMARY KEY,
order_id INT,
2024-04-17 23:19:16 +02:00
manufacture_date DATETIME,
2024-04-16 20:49:39 +02:00
delivery_date DATE,
2024-04-17 23:19:16 +02:00
blocked VARCHAR(255) DEFAULT 'no',
cookie_name VARCHAR(255),
FOREIGN KEY(cookie_name) REFERENCES Cookie(name),
FOREIGN KEY (order_id) REFERENCES Orders(order_id)
2024-04-16 20:49:39 +02:00
);
CREATE TABLE OrderSpec (
order_id INT,
2024-04-17 23:19:16 +02:00
cookie_name VARCHAR(255),
2024-04-16 20:49:39 +02:00
quantity INT,
2024-04-17 23:19:16 +02:00
PRIMARY KEY (order_id, cookie_name),
FOREIGN KEY (order_id) REFERENCES Orders(order_id),
2024-04-17 23:19:16 +02:00
FOREIGN KEY (cookie_name) REFERENCES Cookie(name)
2024-04-16 20:49:39 +02:00
);
CREATE TABLE Ingredient (
2024-04-17 23:19:16 +02:00
ingredient_name VARCHAR(255) PRIMARY KEY,
2024-04-16 20:49:39 +02:00
stock INT,
unit VARCHAR(50),
delivery_date DATE,
delivery_amount INT
);
CREATE TABLE Recipe (
2024-04-17 23:19:16 +02:00
ingredient_name VARCHAR(255),
cookie_name VARCHAR(255),
2024-04-16 20:49:39 +02:00
amount FLOAT,
2024-04-17 23:19:16 +02:00
PRIMARY KEY (ingredient_name, cookie_name),
FOREIGN KEY (ingredient_name) REFERENCES Ingredient(ingredient_name),
FOREIGN KEY (cookie_name) REFERENCES Cookie(name)
2024-04-16 20:49:39 +02:00
);