Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
MykhailoIvchenko committed Dec 27, 2024
1 parent 3be71e7 commit 7ab19a6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ide
.vscode
.idea
vscode
72 changes: 54 additions & 18 deletions task.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,66 @@ CREATE DATABASE ShopDB;
USE ShopDB;

CREATE TABLE Countries (
ID INT,
ID INT AUTO_INCREMENT,
Name VARCHAR(50),
PRIMARY KEY (ID)
);

CREATE TABLE Cities (
ID INT AUTO_INCREMENT,
Name VARCHAR(50),
CountryID INT,
FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION,
PRIMARY KEY (ID)
);

CREATE TABLE Addresses (
ID INT AUTO_INCREMENT,
StreetName VARCHAR(100),
CityID INT,
FOREIGN KEY (CityID) REFERENCES Cities(ID) ON DELETE NO ACTION,
PRIMARY KEY (ID)
);

CREATE TABLE Warehouses (
ID INT AUTO_INCREMENT,
Name VARCHAR(50),
AddressID INT,
FOREIGN KEY (AddressID) REFERENCES Addresses(ID) ON DELETE NO ACTION,
PRIMARY KEY (ID)
)

CREATE TABLE ProductInventory (
ID INT,
ProductName VARCHAR(50),
WarehouseAmount INT,
WarehouseName VARCHAR(50),
WarehouseAddress VARCHAR(50),
CountryID INT,
FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION,
PRIMARY KEY (ID)
ID INT AUTO_INCREMENT,
ProductName VARCHAR(50),
WarehouseAmount INT,
WarehouseID INT,
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 Countries (Name)
VALUES ('Country1');
INSERT INTO Countries (Name)
VALUES ('Country2');

INSERT INTO Cities(Name, CountryID)
VALUES ('City-1', 1)

INSERT INTO Cities(Name, CountryID)
VALUES ('City-2', 2)

INSERT INTO Addresses(StreetName, CityID)
VALUES ('Street-1', 1)

INSERT INTO Addresses(StreetName, CityID)
VALUES ('Street-2', 2)

INSERT INTO Warehouses (Name, AddressID)
VALUES ('Warehouse-1', 1)
INSERT INTO ProductInventory (ProductName,WarehouseAmount, WarehouseID)
VALUES ('AwersomeProduct', 2, 1);
INSERT INTO ProductInventory (ProductName,WarehouseAmount, WarehouseID)
VALUES ('AwersomeProduct', 5, 2);

0 comments on commit 7ab19a6

Please sign in to comment.