From 71810987013e33f2ca143feaebd82cdb68e88f4b Mon Sep 17 00:00:00 2001 From: elfredburger Date: Wed, 24 Jul 2024 15:56:47 +0200 Subject: [PATCH 1/2] Solution --- task.sql | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/task.sql b/task.sql index 0a66d93..8d1f0ab 100644 --- a/task.sql +++ b/task.sql @@ -1 +1,38 @@ -# Write your SQL code for the database creation here. Good luck! +CREATE DATABASE ShopDB; +USE ShopDB; +CREATE TABLE Products( + ID INT AUTO_INCREMENT, + Name VARCHAR(50), + Description VARCHAR(100), + Price INT, + WareHouseAmount INT, + PRIMARY KEY(ID) +); + +CREATE TABLE Customers( + ID INT AUTO_INCREMENT, + FirstName VARCHAR(50), + LastName VARCHAR(50), + Email VARCHAR(50), + Address VARCHAR(100), + PRIMARY KEY(ID) +); + +CREATE TABLE Orders( + ID INT AUTO_INCREMENT, + CustomerID INT, + Date DATE, + PRIMARY KEY (ID), + FOREIGN KEY (CustomerID) REFERENCES Customers.ID ON DELETE SET NULL + +); + +CREATE TABLE OrderItems( + ID INT AUTO_INCREMENT, + OrderID INT, + ProductID INT, + PRIMARY KEY (ID), + FOREIGN KEY (OrderID) REFERENCES Orders.ID ON DELETE SET NULL, + FOREIGN KEY (ProductID) REFERENCES Products.ID ON DELETE SET NULL + +); From eaf7e3353f05ac5c1a0a9815b7e797e07e423f5a Mon Sep 17 00:00:00 2001 From: elfredburger Date: Wed, 24 Jul 2024 15:58:42 +0200 Subject: [PATCH 2/2] Solution --- task.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/task.sql b/task.sql index 8d1f0ab..31c7dae 100644 --- a/task.sql +++ b/task.sql @@ -23,7 +23,7 @@ CREATE TABLE Orders( CustomerID INT, Date DATE, PRIMARY KEY (ID), - FOREIGN KEY (CustomerID) REFERENCES Customers.ID ON DELETE SET NULL + FOREIGN KEY (CustomerID) REFERENCES Customers(ID) ON DELETE SET NULL ); @@ -32,7 +32,7 @@ CREATE TABLE OrderItems( OrderID INT, ProductID INT, PRIMARY KEY (ID), - FOREIGN KEY (OrderID) REFERENCES Orders.ID ON DELETE SET NULL, - FOREIGN KEY (ProductID) REFERENCES Products.ID ON DELETE SET NULL + FOREIGN KEY (OrderID) REFERENCES Orders(ID) ON DELETE SET NULL, + FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE SET NULL );