diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..d843f34 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/task.sql b/task.sql index cc65344..19390e5 100644 --- a/task.sql +++ b/task.sql @@ -1,33 +1,52 @@ -- Create database and tables +DROP DATABASE IF EXISTS ShopDB; CREATE DATABASE ShopDB; USE ShopDB; CREATE TABLE Countries ( - ID INT, + ID INT PRIMARY KEY AUTO_INCREMENT, Name VARCHAR(50), - 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) +CREATE TABLE Products ( + ID INT PRIMARY KEY AUTO_INCREMENT, + ProductName VARCHAR(50) ); --- Populate test data +CREATE TABLE Warehouses ( + ID INT PRIMARY KEY AUTO_INCREMENT, + WarehouseName VARCHAR(50) NOT NULL, + WarehouseAddress VARCHAR(50) NOT NULL, + CountryID INT NOT NULL, + FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION +); + +CREATE TABLE Inventory ( + ID INT PRIMARY KEY AUTO_INCREMENT, + ProductID INT NOT NULL, + WarehouseID INT NOT NULL, + WarehouseAmount INT NOT NULL, + FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE CASCADE, + FOREIGN KEY (WarehouseID) REFERENCES Warehouses(ID) ON DELETE CASCADE +); -INSERT INTO Countries (ID,Name) - VALUES (1, 'Country1'); -INSERT INTO Countries (ID,Name) - VALUES (2, 'Country2'); +INSERT INTO Countries (Name) + VALUES ('Country1'); +INSERT INTO Countries (Name) + VALUES ('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 (ProductName) + VALUES ('AwesomeProduct'); +INSERT INTO Products (ProductName) + VALUES ('AwesomeProduct2'); + +INSERT INTO Warehouses (WarehouseName, WarehouseAddress, CountryID) + VALUES ('warehouse1', 'city-1, street-1', 1); +INSERT INTO Warehouses (WarehouseName, WarehouseAddress, CountryID) + VALUES ('warehouse2', 'city-2, street-2', 2); + +INSERT INTO Inventory (ProductID, WarehouseID, WarehouseAmount) + VALUES (1, 1, 2); +INSERT INTO Inventory (ProductID, WarehouseID, WarehouseAmount) + VALUES (2, 2, 3); \ No newline at end of file