From 2d02f782d76f070ad254e428d607816518d7a70c Mon Sep 17 00:00:00 2001 From: Illia Losiev Date: Sat, 31 Aug 2024 12:17:40 +0300 Subject: [PATCH] 'Solution' --- task.sql | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/task.sql b/task.sql index cc65344..1624e75 100644 --- a/task.sql +++ b/task.sql @@ -1,33 +1,54 @@ --- Create database and tables - CREATE DATABASE ShopDB; USE ShopDB; CREATE TABLE Countries ( - ID INT, + ID INT auto_increment, Name VARCHAR(50), PRIMARY KEY (ID) ); -CREATE TABLE ProductInventory ( - ID INT, - ProductName VARCHAR(50), - WarehouseAmount INT, - WarehouseName VARCHAR(50), - WarehouseAddress VARCHAR(50), +CREATE TABLE Products ( + ID INT AUTO_INCREMENT, + Name VARCHAR(50), + PRIMARY KEY (ID) +); + +CREATE TABLE Warehouses ( + ID INT AUTO_INCREMENT, + Name VARCHAR(50), + Address VARCHAR(50), CountryID INT, FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION, PRIMARY KEY (ID) ); --- Populate test data +CREATE TABLE ProductInventory ( + ID INT, + ProductID INT, + FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE NO ACTION, + Amount INT, + WarehouseID INT, + FOREIGN KEY (WarehouseID) 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 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 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,ProductID,Amount,WarehouseID) + VALUES (1, 1, 2, 1); + +INSERT INTO ProductInventory (ID,ProductID,Amount,WarehouseID) + VALUES (2, 1, 5, 2);