From d90fd87ea1c00d0db7ab6feacb823fbbb62bd1b1 Mon Sep 17 00:00:00 2001 From: Yakov K Date: Tue, 23 Jul 2024 14:45:49 +0300 Subject: [PATCH 1/3] NormalizationSolution --- task.sql | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/task.sql b/task.sql index cc65344..79c9fe7 100644 --- a/task.sql +++ b/task.sql @@ -5,29 +5,50 @@ USE ShopDB; CREATE TABLE Countries ( ID INT, - Name VARCHAR(50), + Name VARCHAR(30), PRIMARY KEY (ID) ); -CREATE TABLE ProductInventory ( - ID INT, - ProductName VARCHAR(50), - WarehouseAmount INT, - WarehouseName VARCHAR(50), - WarehouseAddress VARCHAR(50), - CountryID INT, +CREATE TABLE Products ( + ID INT AUTO_INCREMENT, + Name VARCHAR(30), + PRIMARY KEY(ID) +); + +CREATE TABLE Warehouses ( + ID INT AUTO_INCREMENT, + Name VARCHAR(30) + Address VARCHAR(50) + CountryID INT, FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION, PRIMARY KEY (ID) ); +CREATE TABLE ProductInventory ( + ID INT AUTO_INCREMENT, + ProductID INT, + FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE NO ACTION, + WarehouseAmount INT, + WarehouseID INT, + FOREIGN KEY (WarehouseID) REFERENCES Warehouses(ID) ON DELETE NO ACTION, + PRIMARY KEY (ID) +); -- Populate test data INSERT INTO Countries (ID,Name) VALUES (1, 'Country1'); INSERT INTO Countries (ID,Name) VALUES (2, 'Country2'); + +INSERT INTO Products (Name) + VALUES ('AwersomeProduct'); + +INSERT INTO Warehouses (Name, Address, CountryID) + VALUES ('Warehouse-1', 'City-1, Street-1', 1); +INSERT INTO Warehouses (Name, Address, CountryID) + VALUES ('Warehouse-2', 'City-2, Street-2', 2); -INSERT INTO ProductInventory (ID,ProductName,WarehouseAmount,WarehouseName,WarehouseAddress,CountryID) - VALUES (1, 'AwersomeProduct', 2, 'Warehouse-1', 'City-1, Street-1',1); -INSERT INTO ProductInventory (ID,ProductName,WarehouseAmount,WarehouseName,WarehouseAddress,CountryID) - VALUES (2, 'AwersomeProduct', 5, 'Warehouse-2', 'City-2, Street-2',2); +INSERT INTO ProductInventory (ID,ProductID,WarehouseAmount,WarehouseID) + VALUES (1, 1, 1, 2); +INSERT INTO ProductInventory (ID,ProductID,WarehouseAmount,WarehouseID) + VALUES (2, 1, 6, 2); \ No newline at end of file From 5783c2226f1d44618d9a257f11c7de0d15ce2fa4 Mon Sep 17 00:00:00 2001 From: Yakov K Date: Tue, 23 Jul 2024 14:51:52 +0300 Subject: [PATCH 2/3] NormalizationSolution2 --- task.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/task.sql b/task.sql index 79c9fe7..82956a0 100644 --- a/task.sql +++ b/task.sql @@ -17,8 +17,8 @@ CREATE TABLE Products ( CREATE TABLE Warehouses ( ID INT AUTO_INCREMENT, - Name VARCHAR(30) - Address VARCHAR(50) + Name VARCHAR(30), + Address VARCHAR(50), CountryID INT, FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION, PRIMARY KEY (ID) From d0e1dd69cbbd44c05faa6ab0c0b89719c27349d5 Mon Sep 17 00:00:00 2001 From: Yakov K Date: Tue, 23 Jul 2024 21:03:18 +0300 Subject: [PATCH 3/3] criticalfix --- task.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task.sql b/task.sql index 82956a0..a684242 100644 --- a/task.sql +++ b/task.sql @@ -51,4 +51,4 @@ INSERT INTO Warehouses (Name, Address, CountryID) INSERT INTO ProductInventory (ID,ProductID,WarehouseAmount,WarehouseID) VALUES (1, 1, 1, 2); INSERT INTO ProductInventory (ID,ProductID,WarehouseAmount,WarehouseID) - VALUES (2, 1, 6, 2); \ No newline at end of file + VALUES (2, 1, 6, 2);