From f1ba2dce8dc9fae167fb4b7d5a76cb5b17f66ab5 Mon Sep 17 00:00:00 2001 From: Kulib Date: Wed, 11 Sep 2024 00:36:33 +0300 Subject: [PATCH] first commit --- task.sql | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/task.sql b/task.sql index cc65344..41266f8 100644 --- a/task.sql +++ b/task.sql @@ -9,10 +9,14 @@ 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), CountryID INT, @@ -20,14 +24,34 @@ CREATE TABLE ProductInventory ( PRIMARY KEY (ID) ); +CREATE TABLE ProductInventory ( + ID INT, + ProductID INT, + WarehouseAmount INT, + WarehouseID INT, + FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE NO ACTION, + FOREIGN KEY (WarehouseID) REFERENCES Warehouses(ID) ON DELETE NO ACTION, + PRIMARY KEY (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 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,ProductID,WarehouseAmount,WarehouseID) + VALUES (1, 1, 2, 1); +INSERT INTO ProductInventory (ID,ProductID,WarehouseAmount,WarehouseID) + VALUES (2, 2, 5,2);