-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3be71e7
commit 44b7821
Showing
1 changed file
with
42 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |