Uppdaterad sqlkod

This commit is contained in:
Ivan Bogosavljevic 2024-04-17 23:19:16 +02:00 committed by GitHub
parent 051c15d8d3
commit eb38c47af7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

38
sqlCode
View file

@ -1,8 +1,8 @@
DROP TABLE IF EXISTS OrderSpec; DROP TABLE IF EXISTS OrderSpec;
DROP TABLE IF EXISTS Recipe; DROP TABLE IF EXISTS Recipe;
DROP TABLE IF EXISTS Ingredient; DROP TABLE IF EXISTS Ingredient;
DROP TABLE IF EXISTS Cookie;
DROP TABLE IF EXISTS Pallet; DROP TABLE IF EXISTS Pallet;
DROP TABLE IF EXISTS Cookie;
DROP TABLE IF EXISTS Orders; DROP TABLE IF EXISTS Orders;
DROP TABLE IF EXISTS Customer; DROP TABLE IF EXISTS Customer;
@ -20,34 +20,32 @@ CREATE TABLE Orders (
FOREIGN KEY (customer_id) REFERENCES Customer(customer_id) FOREIGN KEY (customer_id) REFERENCES Customer(customer_id)
); );
CREATE TABLE Cookie (
name VARCHAR(255) PRIMARY KEY
);
CREATE TABLE Pallet ( CREATE TABLE Pallet (
pallet_id INT AUTO_INCREMENT PRIMARY KEY, pallet_id INT AUTO_INCREMENT PRIMARY KEY,
order_id INT, order_id INT,
manufacture_date DATE, manufacture_date DATETIME,
delivery_date DATE, delivery_date DATE,
blocked BOOLEAN, blocked VARCHAR(255) DEFAULT 'no',
cookie_name VARCHAR(255),
FOREIGN KEY(cookie_name) REFERENCES Cookie(name),
FOREIGN KEY (order_id) REFERENCES Orders(order_id) FOREIGN KEY (order_id) REFERENCES Orders(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 ( CREATE TABLE OrderSpec (
order_id INT, order_id INT,
cookie_id INT, cookie_name VARCHAR(255),
quantity INT, quantity INT,
PRIMARY KEY (order_id, cookie_id), PRIMARY KEY (order_id, cookie_name),
FOREIGN KEY (order_id) REFERENCES Orders(order_id), FOREIGN KEY (order_id) REFERENCES Orders(order_id),
FOREIGN KEY (cookie_id) REFERENCES Cookie(cookie_id) FOREIGN KEY (cookie_name) REFERENCES Cookie(name)
); );
CREATE TABLE Ingredient ( CREATE TABLE Ingredient (
ingredient_id INT AUTO_INCREMENT PRIMARY KEY, ingredient_name VARCHAR(255) PRIMARY KEY,
name VARCHAR(255),
stock INT, stock INT,
unit VARCHAR(50), unit VARCHAR(50),
delivery_date DATE, delivery_date DATE,
@ -55,10 +53,10 @@ CREATE TABLE Ingredient (
); );
CREATE TABLE Recipe ( CREATE TABLE Recipe (
ingredient_id INT, ingredient_name VARCHAR(255),
cookie_id INT, cookie_name VARCHAR(255),
amount FLOAT, amount FLOAT,
PRIMARY KEY (ingredient_id, cookie_id), PRIMARY KEY (ingredient_name, cookie_name),
FOREIGN KEY (ingredient_id) REFERENCES Ingredient(ingredient_id), FOREIGN KEY (ingredient_name) REFERENCES Ingredient(ingredient_name),
FOREIGN KEY (cookie_id) REFERENCES Cookie(cookie_id) FOREIGN KEY (cookie_name) REFERENCES Cookie(name)
); );