From 3c6f7d9f225c4612494e70b6b74a4b9f34ecad54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=94=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=BB=D1=96=D0=B2?= Date: Tue, 20 Aug 2024 10:11:24 +0300 Subject: [PATCH 1/3] Solution --- task.sql | 72 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 19 deletions(-) diff --git a/task.sql b/task.sql index cc65344..6ad2e5f 100644 --- a/task.sql +++ b/task.sql @@ -1,33 +1,67 @@ --- 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 City ( + ID INT AUTO_INCREMENT, Name VARCHAR(50), PRIMARY KEY (ID) ); +CREATE TABLE Street ( + ID INT AUTO_INCREMENT, + Name VARCHAR(50), + PRIMARY KEY (ID) +); + +CREATE TABLE WarehouseAddresses ( + ID INT AUTO_INCREMENT, + CityID INT, + StreetID INT, + PRIMARY KEY (ID), + FOREIGN KEY (CityID) REFERENCES City(ID), + FOREIGN KEY (StreetID) REFERENCES Street(ID) +); + +CREATE TABLE Warehouses ( + ID INT AUTO_INCREMENT, + Name VARCHAR(50), + AddressID INT, + PRIMARY KEY (ID), + FOREIGN KEY (AddressID) REFERENCES WarehouseAddresses(ID) +); + CREATE TABLE ProductInventory ( - ID INT, + ID INT AUTO_INCREMENT, ProductName VARCHAR(50), WarehouseAmount INT, - WarehouseName VARCHAR(50), - WarehouseAddress VARCHAR(50), + WarehouseID INT, CountryID INT, - FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION, - PRIMARY KEY (ID) + PRIMARY KEY (ID), + FOREIGN KEY (WarehouseID) REFERENCES Warehouses(ID), + FOREIGN KEY (CountryID) REFERENCES Countries(ID) ); --- 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 (Name) + VALUES ('Country-1'), ('Country-2'); + +INSERT INTO City (Name) + VALUES ('City-1'), ('City-2'); + +INSERT INTO Street (Name) + VALUES ('Street-1'), ('Street-2'); + +INSERT INTO WarehouseAddresses (CityID, StreetID) + VALUES (1, 1), (2, 2); + +INSERT INTO Warehouses (Name, AddressID) + VALUES ('Warehouse-1', 1), ('Warehouse-2', 2); + +INSERT INTO ProductInventory (ProductName, WarehouseAmount, WarehouseID, CountryID) + VALUES ('AwersomeProduct', 2, 1, 1), ('AwersomeProduct', 5, 2, 2); From cf770e87bc489739621ee94683af704b2876e217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=94=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=BB=D1=96=D0=B2?= Date: Tue, 20 Aug 2024 10:19:05 +0300 Subject: [PATCH 2/3] fix Solution --- task.sql | 68 +++++++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/task.sql b/task.sql index 6ad2e5f..a64a4f8 100644 --- a/task.sql +++ b/task.sql @@ -7,61 +7,49 @@ CREATE TABLE Countries ( PRIMARY KEY (ID) ); -CREATE TABLE City ( - ID INT AUTO_INCREMENT, - Name VARCHAR(50), - PRIMARY KEY (ID) -); - -CREATE TABLE Street ( - ID INT AUTO_INCREMENT, +CREATE TABLE Products ( + ID INT AUTO_INCREMENT, Name VARCHAR(50), PRIMARY KEY (ID) ); -CREATE TABLE WarehouseAddresses ( - ID INT AUTO_INCREMENT, - CityID INT, - StreetID INT, - PRIMARY KEY (ID), - FOREIGN KEY (CityID) REFERENCES City(ID), - FOREIGN KEY (StreetID) REFERENCES Street(ID) -); - CREATE TABLE Warehouses ( - ID INT AUTO_INCREMENT, + ID INT AUTO_INCREMENT, Name VARCHAR(50), - AddressID INT, - PRIMARY KEY (ID), - FOREIGN KEY (AddressID) REFERENCES WarehouseAddresses(ID) + Address VARCHAR(50), + CountryID INT, + FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION, + PRIMARY KEY (ID) ); CREATE TABLE ProductInventory ( - ID INT AUTO_INCREMENT, - ProductName VARCHAR(50), - WarehouseAmount INT, + ID INT, + ProductID INT, + FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE NO ACTION, + Amount INT, WarehouseID INT, - CountryID INT, - PRIMARY KEY (ID), - FOREIGN KEY (WarehouseID) REFERENCES Warehouses(ID), - FOREIGN KEY (CountryID) REFERENCES Countries(ID) + FOREIGN KEY (WarehouseID) REFERENCES Warehouses(ID) ON DELETE NO ACTION, + PRIMARY KEY (ID) ); -INSERT INTO Countries (Name) - VALUES ('Country-1'), ('Country-2'); +INSERT INTO Countries (ID,Name) + VALUES (1, 'Country1'); + +INSERT INTO Countries (ID,Name) + VALUES (2, 'Country2'); -INSERT INTO City (Name) - VALUES ('City-1'), ('City-2'); +INSERT INTO Products (Name) + VALUES ('AwersomeProduct'); -INSERT INTO Street (Name) - VALUES ('Street-1'), ('Street-2'); +INSERT INTO Warehouses (Name, Address, CountryID) + VALUES ('Warehouse-1', 'City-1, Street-1', 1); -INSERT INTO WarehouseAddresses (CityID, StreetID) - VALUES (1, 1), (2, 2); +INSERT INTO Warehouses (Name, Address, CountryID) + VALUES ('Warehouse-2', 'City-2, Street-2', 2); -INSERT INTO Warehouses (Name, AddressID) - VALUES ('Warehouse-1', 1), ('Warehouse-2', 2); +INSERT INTO ProductInventory (ID,ProductID,Amount,WarehouseID) + VALUES (1, 1, 2, 1); -INSERT INTO ProductInventory (ProductName, WarehouseAmount, WarehouseID, CountryID) - VALUES ('AwersomeProduct', 2, 1, 1), ('AwersomeProduct', 5, 2, 2); +INSERT INTO ProductInventory (ID,ProductID,Amount,WarehouseID) + VALUES (2, 1, 5, 2); \ No newline at end of file From e7cd7923f584b3eb993dbf82d0a9ff14d88d3d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=94=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=BB=D1=96=D0=B2?= Date: Tue, 20 Aug 2024 23:11:07 +0300 Subject: [PATCH 3/3] fix EoF --- task.sql | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/task.sql b/task.sql index a64a4f8..4512597 100644 --- a/task.sql +++ b/task.sql @@ -14,7 +14,7 @@ CREATE TABLE Products ( ); CREATE TABLE Warehouses ( - ID INT AUTO_INCREMENT, + ID INT AUTO_INCREMENT, Name VARCHAR(50), Address VARCHAR(50), CountryID INT, @@ -32,7 +32,6 @@ CREATE TABLE ProductInventory ( PRIMARY KEY (ID) ); - INSERT INTO Countries (ID,Name) VALUES (1, 'Country1'); @@ -52,4 +51,4 @@ INSERT INTO ProductInventory (ID,ProductID,Amount,WarehouseID) VALUES (1, 1, 2, 1); INSERT INTO ProductInventory (ID,ProductID,Amount,WarehouseID) - VALUES (2, 1, 5, 2); \ No newline at end of file + VALUES (2, 1, 5, 2);