From cfe73eb37c6656e50b70d535117fe961fa940e2f Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 7 Jan 2026 18:51:04 +0200 Subject: [PATCH 1/3] Solution --- task.sql | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/task.sql b/task.sql index cc65344..185b9df 100644 --- a/task.sql +++ b/task.sql @@ -9,14 +9,29 @@ CREATE TABLE Countries ( PRIMARY KEY (ID) ); -CREATE TABLE ProductInventory ( - ID INT, +CREATE TABLE Warehouse( + ID INT AUTO_INCREMENT, + WarehouseName VARCHAR(50), + WarehouseAddressCity VARCHAR(50), + WarehouseAddressStreet VARCHAR(50), + PRIMARY KEY (ID) +); + +CREATE TABLE ProductAmount( + ID INT AUTO_INCREMENT, ProductName VARCHAR(50), WarehouseAmount INT, - WarehouseName VARCHAR(50), - WarehouseAddress VARCHAR(50), + PRIMARY KEY (ID) +); + +CREATE TABLE ProductInventory ( + ID INT, + WarehouseID INT, + ProductID INT, CountryID INT, FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION, + FOREIGN KEY (ProductID) REFERENCES ProductAmount(ID) ON DELETE NO ACTION, + FOREIGN KEY (WarehouseID) REFERENCES Warehouse(ID) ON DELETE NO ACTION, PRIMARY KEY (ID) ); @@ -26,8 +41,19 @@ INSERT INTO Countries (ID,Name) VALUES (1, 'Country1'); INSERT INTO Countries (ID,Name) VALUES (2, 'Country2'); - -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 Warehouse (ID, WarehouseName, WarehouseAddressCity, WarehouseAddressStreet) + VALUES (1, 'Warehouse-1', 'City-1', 'Street-1'); +INSERT INTO Warehouse (ID, WarehouseName, WarehouseAddressCity, WarehouseAddressStreet) + VALUES (2, 'Warehouse-2', 'City-2', 'Street-2'); + +INSERT INTO ProductAmount (ID, ProductName, WarehouseAmount) + VALUES (1, 'AwersomeProduct', 2); +INSERT INTO ProductAmount (ID, ProductName, WarehouseAmount) + VALUES (2, 'AwersomeProduct', 5); + + +INSERT INTO ProductInventory (ID, WarehouseID, ProductID, CountryID) + VALUES (1, 1, 1, 1); +INSERT INTO ProductInventory (ID, WarehouseID, ProductID, CountryID) + VALUES (2, 2, 2, 2); From 64caeb9483250435bc5696a30d82eb8f17b0ffe8 Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 7 Jan 2026 18:58:49 +0200 Subject: [PATCH 2/3] add column productAmount in ProductInventory and delete column amount in Products --- task.sql | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/task.sql b/task.sql index 185b9df..b879cb8 100644 --- a/task.sql +++ b/task.sql @@ -17,10 +17,9 @@ CREATE TABLE Warehouse( PRIMARY KEY (ID) ); -CREATE TABLE ProductAmount( +CREATE TABLE Products( ID INT AUTO_INCREMENT, ProductName VARCHAR(50), - WarehouseAmount INT, PRIMARY KEY (ID) ); @@ -28,9 +27,10 @@ CREATE TABLE ProductInventory ( ID INT, WarehouseID INT, ProductID INT, + WarehouseAmount INT, CountryID INT, FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION, - FOREIGN KEY (ProductID) REFERENCES ProductAmount(ID) ON DELETE NO ACTION, + FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE NO ACTION, FOREIGN KEY (WarehouseID) REFERENCES Warehouse(ID) ON DELETE NO ACTION, PRIMARY KEY (ID) ); @@ -47,13 +47,13 @@ INSERT INTO Warehouse (ID, WarehouseName, WarehouseAddressCity, WarehouseAddress INSERT INTO Warehouse (ID, WarehouseName, WarehouseAddressCity, WarehouseAddressStreet) VALUES (2, 'Warehouse-2', 'City-2', 'Street-2'); -INSERT INTO ProductAmount (ID, ProductName, WarehouseAmount) - VALUES (1, 'AwersomeProduct', 2); -INSERT INTO ProductAmount (ID, ProductName, WarehouseAmount) - VALUES (2, 'AwersomeProduct', 5); +INSERT INTO Products (ID, ProductName) + VALUES (1, 'AwersomeProduct'); +INSERT INTO ProductAmount (ID, ProductName) + VALUES (2, 'AwersomeProduct'); INSERT INTO ProductInventory (ID, WarehouseID, ProductID, CountryID) - VALUES (1, 1, 1, 1); + VALUES (1, 1, 1, 2, 1); INSERT INTO ProductInventory (ID, WarehouseID, ProductID, CountryID) - VALUES (2, 2, 2, 2); + VALUES (2, 2, 2, 5, 2); From 7f4a2a02e3754914f7ec6da30041bde41ec12eac Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 7 Jan 2026 19:11:58 +0200 Subject: [PATCH 3/3] add column citiesID Warehouse table --- task.sql | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/task.sql b/task.sql index b879cb8..79e3251 100644 --- a/task.sql +++ b/task.sql @@ -14,6 +14,8 @@ CREATE TABLE Warehouse( WarehouseName VARCHAR(50), WarehouseAddressCity VARCHAR(50), WarehouseAddressStreet VARCHAR(50), + CountriesID INT, + FOREIGN KEY (CountriesID) REFERENCES Countries(ID) ON DELETE NO ACTION, PRIMARY KEY (ID) ); @@ -28,8 +30,6 @@ CREATE TABLE ProductInventory ( WarehouseID INT, ProductID INT, WarehouseAmount INT, - CountryID INT, - FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION, FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE NO ACTION, FOREIGN KEY (WarehouseID) REFERENCES Warehouse(ID) ON DELETE NO ACTION, PRIMARY KEY (ID) @@ -42,18 +42,18 @@ INSERT INTO Countries (ID,Name) INSERT INTO Countries (ID,Name) VALUES (2, 'Country2'); -INSERT INTO Warehouse (ID, WarehouseName, WarehouseAddressCity, WarehouseAddressStreet) - VALUES (1, 'Warehouse-1', 'City-1', 'Street-1'); -INSERT INTO Warehouse (ID, WarehouseName, WarehouseAddressCity, WarehouseAddressStreet) - VALUES (2, 'Warehouse-2', 'City-2', 'Street-2'); +INSERT INTO Warehouse (ID, WarehouseName, WarehouseAddressCity, WarehouseAddressStreet, CountriesID) + VALUES (1, 'Warehouse-1', 'City-1', 'Street-1', 1); +INSERT INTO Warehouse (ID, WarehouseName, WarehouseAddressCity, WarehouseAddressStreet, CountriesID) + VALUES (2, 'Warehouse-2', 'City-2', 'Street-2', 2); INSERT INTO Products (ID, ProductName) VALUES (1, 'AwersomeProduct'); -INSERT INTO ProductAmount (ID, ProductName) +INSERT INTO Products (ID, ProductName) VALUES (2, 'AwersomeProduct'); -INSERT INTO ProductInventory (ID, WarehouseID, ProductID, CountryID) - VALUES (1, 1, 1, 2, 1); -INSERT INTO ProductInventory (ID, WarehouseID, ProductID, CountryID) - VALUES (2, 2, 2, 5, 2); +INSERT INTO ProductInventory (ID, WarehouseID, ProductID, WarehouseAmount) + VALUES (1, 1, 1, 2); +INSERT INTO ProductInventory (ID, WarehouseID, ProductID, WarehouseAmount) + VALUES (2, 2, 2, 5);