From 79e95006d822f66f53a399df90ed1a416d149350 Mon Sep 17 00:00:00 2001 From: Mykola Honcharenko Date: Sat, 13 Jun 2026 12:38:00 +0300 Subject: [PATCH 1/3] Solution. --- task.sql | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/task.sql b/task.sql index cc65344..ce58731 100644 --- a/task.sql +++ b/task.sql @@ -1,5 +1,3 @@ --- Create database and tables - CREATE DATABASE ShopDB; USE ShopDB; @@ -9,25 +7,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 ); --- Populate test data +CREATE TABLE ProductInventory ( + ID INT, + ProductID INT, + WarehouseAmount INT, + WarehousesID INT, + FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE NO ACTION, + FOREIGN KEY (WarehousesID) REFERENCES Warehouses(ID) ON DELETE NO ACTION, + PRIMARY KEY (ID) +); 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 Products (ID, ProductName) + VALUES (2, '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,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, WarehousesID) + VALUES (1, 1, 2,1); +INSERT INTO ProductInventory (ID, ProductID, WarehouseAmount, WarehousesID) + VALUES (2,2, 5, 2); \ No newline at end of file From b5a96acac5a5ae2ffdcaffb8d24bf0a14dc65a5d Mon Sep 17 00:00:00 2001 From: Mykola Honcharenko Date: Sat, 13 Jun 2026 12:45:33 +0300 Subject: [PATCH 2/3] Add drop database command in top of the file. --- task.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/task.sql b/task.sql index ce58731..2a7c5b4 100644 --- a/task.sql +++ b/task.sql @@ -1,3 +1,4 @@ +DROP DATABASE ShopDB; CREATE DATABASE ShopDB; USE ShopDB; From 202db75eabeaf251faa318befc7f356fc6069f68 Mon Sep 17 00:00:00 2001 From: Mykola Honcharenko Date: Sat, 13 Jun 2026 12:52:12 +0300 Subject: [PATCH 3/3] A design for deleting a database, with a check for the existence of the database. --- task.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task.sql b/task.sql index 2a7c5b4..fc03d77 100644 --- a/task.sql +++ b/task.sql @@ -1,4 +1,4 @@ -DROP DATABASE ShopDB; +DROP DATABASE IF EXISTS ShopDB; CREATE DATABASE ShopDB; USE ShopDB;