From 9695087e152e60a917b815b1cfe9b7e7fac17cd0 Mon Sep 17 00:00:00 2001 From: "dima.yeromin" Date: Mon, 9 Feb 2026 23:12:41 +0100 Subject: [PATCH 1/3] done --- task.sql | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/task.sql b/task.sql index cc65344..f40b9c1 100644 --- a/task.sql +++ b/task.sql @@ -9,25 +9,47 @@ 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), CountryID INT, - FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION, - PRIMARY KEY (ID) + PRIMARY KEY (ID), + FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION +); + +CREATE TABLE ProductInventory ( + ID INT, + ProductID INT, + WarehouseAmount INT, + WarehouseID INT, + PRIMARY KEY (ID), + FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE NO ACTION, + FOREIGN KEY (WarehouseID) REFERENCES Warehouses(ID) ON DELETE NO ACTION ); -- Populate test data -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 Countries (ID, Name) + VALUES (1, 'Country1'); +INSERT INTO Countries (ID, Name) + VALUES (2, 'Country2'); + +INSERT INTO Products (ID, ProductName) + VALUES (1, 'AwersomeProduct'); + +INSERT INTO Warehouses (ID, WarehouseName, WarehouseAddress, CountryID) + VALUES (1, 'Warehouse-1', 'City-1, Street-1', 1); +INSERT INTO Warehouses (ID, WarehouseName, WarehouseAddress, CountryID) + VALUES (2, 'Warehouse-2', 'City-2, Street-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 be05f8994bece82cd19dd3b2c74cb8c2fc1b2524 Mon Sep 17 00:00:00 2001 From: "dima.yeromin" Date: Mon, 9 Feb 2026 23:18:36 +0100 Subject: [PATCH 2/3] drop --- task.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/task.sql b/task.sql index f40b9c1..cd4b970 100644 --- a/task.sql +++ b/task.sql @@ -1,5 +1,6 @@ -- Create database and tables +DROP DATABASE IF EXISTS ShopDB; CREATE DATABASE ShopDB; USE ShopDB; From e23faeed3ae0975c51a79752fd2bb69fd1eaf9d3 Mon Sep 17 00:00:00 2001 From: "dima.yeromin" Date: Mon, 9 Feb 2026 23:21:00 +0100 Subject: [PATCH 3/3] set the DB save type as InnoDB --- task.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/task.sql b/task.sql index cd4b970..4db8eda 100644 --- a/task.sql +++ b/task.sql @@ -8,13 +8,13 @@ CREATE TABLE Countries ( ID INT, Name VARCHAR(50), PRIMARY KEY (ID) -); +) ENGINE=InnoDB; CREATE TABLE Products ( ID INT, ProductName VARCHAR(50), PRIMARY KEY (ID) -); +) ENGINE=InnoDB; CREATE TABLE Warehouses ( ID INT, @@ -23,7 +23,7 @@ CREATE TABLE Warehouses ( CountryID INT, PRIMARY KEY (ID), FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION -); +) ENGINE=InnoDB; CREATE TABLE ProductInventory ( ID INT, @@ -33,7 +33,7 @@ CREATE TABLE ProductInventory ( PRIMARY KEY (ID), FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE NO ACTION, FOREIGN KEY (WarehouseID) REFERENCES Warehouses(ID) ON DELETE NO ACTION -); +) ENGINE=InnoDB; -- Populate test data