From 53aa3459c978778ef1c38840d7933deef3306ba9 Mon Sep 17 00:00:00 2001 From: shafran Date: Wed, 24 Jun 2026 19:56:51 +0300 Subject: [PATCH 1/4] Done --- task.sql | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/task.sql b/task.sql index cc65344..888e09b 100644 --- a/task.sql +++ b/task.sql @@ -9,12 +9,27 @@ CREATE TABLE Countries ( PRIMARY KEY (ID) ); -CREATE TABLE ProductInventory ( +CREATE TABLE Products ( ID INT, ProductName VARCHAR(50), - WarehouseAmount INT, + PRIMARY KEY (ID) +); + +CREATE TABLE Warehouses ( + ID INT, WarehouseName VARCHAR(50), - WarehouseAddress VARCHAR(50), + WarehouseAddress VARCHAR(50), + PRIMARY KEY (ID) +); + + +CREATE TABLE ProductInventory ( + ID INT, + ProductID INT, + FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE CASCADE, + WarehouseAmount INT, + WarehouseID INT, + FOREIGN KEY (WarehouseID) REFERENCES Warehouses(ID) ON DELETE CASCADE, CountryID INT, FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION, PRIMARY KEY (ID) @@ -27,7 +42,7 @@ INSERT INTO Countries (ID,Name) 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 ProductInventory (ID,ProductID,WarehouseAmount,WarehouseID,CountryID) + VALUES (1, 1, 2, 1, 1); +INSERT INTO ProductInventory (ID,ProductID,WarehouseAmount,WarehouseID,CountryID) + VALUES (2, 1, 5, 2, 2); From 8da77b3fac5dd3498226d5d7ff4e538072d20f7f Mon Sep 17 00:00:00 2001 From: shafran Date: Wed, 24 Jun 2026 20:23:46 +0300 Subject: [PATCH 2/4] fix in task.sql --- task.sql | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/task.sql b/task.sql index 888e09b..1adea45 100644 --- a/task.sql +++ b/task.sql @@ -41,7 +41,18 @@ INSERT INTO Countries (ID,Name) VALUES (1, 'Country1'); INSERT INTO Countries (ID,Name) VALUES (2, 'Country2'); - + +INSERT INTO Products (ID,ProductName) + VALUES (1, 'Product1'); +INSERT INTO Products (ID,ProductName) + VALUES (2, 'Product2'); + +INSERT INTO Warehouses (ID,WarehouseName,WarehouseAddress) + VALUES (1, 'Warehouse1', 'Address1'); + +INSERT INTO Warehouses (ID,WarehouseName,WarehouseAddress) + VALUES (2, 'Warehouse2', 'Address2'); + INSERT INTO ProductInventory (ID,ProductID,WarehouseAmount,WarehouseID,CountryID) VALUES (1, 1, 2, 1, 1); INSERT INTO ProductInventory (ID,ProductID,WarehouseAmount,WarehouseID,CountryID) From d18cd98f1f548344ecdc484e53f146ea0913e4d4 Mon Sep 17 00:00:00 2001 From: shafran Date: Wed, 24 Jun 2026 20:27:40 +0300 Subject: [PATCH 3/4] final fix --- task.sql | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/task.sql b/task.sql index 1adea45..25834d6 100644 --- a/task.sql +++ b/task.sql @@ -19,6 +19,8 @@ CREATE TABLE Warehouses ( ID INT, WarehouseName VARCHAR(50), WarehouseAddress VARCHAR(50), + CountryID INT, + FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION, PRIMARY KEY (ID) ); @@ -30,8 +32,6 @@ CREATE TABLE ProductInventory ( WarehouseAmount INT, WarehouseID INT, FOREIGN KEY (WarehouseID) REFERENCES Warehouses(ID) ON DELETE CASCADE, - CountryID INT, - FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION, PRIMARY KEY (ID) ); @@ -47,13 +47,13 @@ INSERT INTO Products (ID,ProductName) INSERT INTO Products (ID,ProductName) VALUES (2, 'Product2'); -INSERT INTO Warehouses (ID,WarehouseName,WarehouseAddress) - VALUES (1, 'Warehouse1', 'Address1'); +INSERT INTO Warehouses (ID,WarehouseName,WarehouseAddress,CountryID) + VALUES (1, 'Warehouse1', 'Address1', 1); -INSERT INTO Warehouses (ID,WarehouseName,WarehouseAddress) - VALUES (2, 'Warehouse2', 'Address2'); +INSERT INTO Warehouses (ID,WarehouseName,WarehouseAddress,CountryID) + VALUES (2, 'Warehouse2', 'Address2', 2); -INSERT INTO ProductInventory (ID,ProductID,WarehouseAmount,WarehouseID,CountryID) - VALUES (1, 1, 2, 1, 1); -INSERT INTO ProductInventory (ID,ProductID,WarehouseAmount,WarehouseID,CountryID) - VALUES (2, 1, 5, 2, 2); +INSERT INTO ProductInventory (ID,ProductID,WarehouseAmount,WarehouseID) + VALUES (1, 1, 2, 1); +INSERT INTO ProductInventory (ID,ProductID,WarehouseAmount,WarehouseID) + VALUES (2, 1, 5, 2); From 6c2471732901a48849f653c0f73da13deeee63f5 Mon Sep 17 00:00:00 2001 From: shafran Date: Wed, 24 Jun 2026 20:52:25 +0300 Subject: [PATCH 4/4] fix --- task.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/task.sql b/task.sql index 25834d6..1de9c4f 100644 --- a/task.sql +++ b/task.sql @@ -10,13 +10,13 @@ CREATE TABLE Countries ( ); CREATE TABLE Products ( - ID INT, + ID INT AUTO_INCREMENT, ProductName VARCHAR(50), PRIMARY KEY (ID) ); CREATE TABLE Warehouses ( - ID INT, + ID INT AUTO_INCREMENT, WarehouseName VARCHAR(50), WarehouseAddress VARCHAR(50), CountryID INT, @@ -26,7 +26,7 @@ CREATE TABLE Warehouses ( CREATE TABLE ProductInventory ( - ID INT, + ID INT AUTO_INCREMENT, ProductID INT, FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE CASCADE, WarehouseAmount INT,