diff --git a/sqlCode b/sqlCode index 2205047..9a1dfff 100644 --- a/sqlCode +++ b/sqlCode @@ -1,8 +1,8 @@ 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 Cookie; DROP TABLE IF EXISTS Orders; DROP TABLE IF EXISTS Customer; @@ -20,34 +20,32 @@ CREATE TABLE Orders ( FOREIGN KEY (customer_id) REFERENCES Customer(customer_id) ); +CREATE TABLE Cookie ( + name VARCHAR(255) PRIMARY KEY +); + CREATE TABLE Pallet ( pallet_id INT AUTO_INCREMENT PRIMARY KEY, order_id INT, - manufacture_date DATE, + manufacture_date DATETIME, 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) ); -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, + cookie_name VARCHAR(255), quantity INT, - PRIMARY KEY (order_id, cookie_id), + PRIMARY KEY (order_id, cookie_name), 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 ( - ingredient_id INT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255), + ingredient_name VARCHAR(255) PRIMARY KEY, stock INT, unit VARCHAR(50), delivery_date DATE, @@ -55,10 +53,10 @@ CREATE TABLE Ingredient ( ); CREATE TABLE Recipe ( - ingredient_id INT, - cookie_id INT, + ingredient_name VARCHAR(255), + cookie_name VARCHAR(255), amount FLOAT, - PRIMARY KEY (ingredient_id, cookie_id), - FOREIGN KEY (ingredient_id) REFERENCES Ingredient(ingredient_id), - FOREIGN KEY (cookie_id) REFERENCES Cookie(cookie_id) + PRIMARY KEY (ingredient_name, cookie_name), + FOREIGN KEY (ingredient_name) REFERENCES Ingredient(ingredient_name), + FOREIGN KEY (cookie_name) REFERENCES Cookie(name) );