Skip to content

Commit

Permalink
2
Browse files Browse the repository at this point in the history
  • Loading branch information
zaebalsya1 committed Dec 19, 2024
1 parent 3be71e7 commit 44b7821
Showing 1 changed file with 42 additions and 19 deletions.
61 changes: 42 additions & 19 deletions task.sql
Original file line number Diff line number Diff line change
@@ -1,33 +1,56 @@
-- Create database and tables

-- Drop and recreate the database
DROP DATABASE IF EXISTS ShopDB;
CREATE DATABASE ShopDB;
USE ShopDB;

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

-- Create Products table
CREATE TABLE Products (
ID INT AUTO_INCREMENT,
Name VARCHAR(50),
PRIMARY KEY (ID)
);

-- Create Warehouses table
CREATE TABLE Warehouses (
ID INT AUTO_INCREMENT,
Name VARCHAR(50),
Address VARCHAR(100),
CountryID INT,
PRIMARY KEY (ID),
FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION
);

-- Create ProductInventory table
CREATE TABLE ProductInventory (
ID INT,
ProductName VARCHAR(50),
ID INT AUTO_INCREMENT,
ProductID INT,
WarehouseID INT,
WarehouseAmount INT,
WarehouseName VARCHAR(50),
WarehouseAddress VARCHAR(50),
CountryID INT,
FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION,
PRIMARY KEY (ID)
PRIMARY KEY (ID),
FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE CASCADE,
FOREIGN KEY (WarehouseID) REFERENCES Warehouses(ID) ON DELETE CASCADE
);

-- 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);
-- Countries
INSERT INTO Countries (Name) VALUES ('Country1');
INSERT INTO Countries (Name) VALUES ('Country2');

-- Products
INSERT INTO Products (Name) VALUES ('AwersomeProduct');

-- Warehouses
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);

-- ProductInventory
INSERT INTO ProductInventory (ProductID, WarehouseID, WarehouseAmount) VALUES (1, 1, 2);
INSERT INTO ProductInventory (ProductID, WarehouseID, WarehouseAmount) VALUES (1, 2, 5);

0 comments on commit 44b7821

Please sign in to comment.