-
Notifications
You must be signed in to change notification settings - Fork 155
solution1 #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
solution1 #160
Changes from all commits
456c505
b3b844e
726e40e
5cb1c3b
c2cf9b7
ef19a5c
4b7b316
ba21dd9
f4fe43a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,51 @@ | ||
| -- Create database and tables | ||
| DROP DATABASE IF EXISTS ShopDB; | ||
|
|
||
| CREATE DATABASE ShopDB; | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This script will fail because you're trying to use the |
||
|
|
||
| USE ShopDB; | ||
|
|
||
| CREATE TABLE Countries ( | ||
| ID INT, | ||
| Name VARCHAR(50), | ||
| PRIMARY KEY (ID) | ||
|
|
||
| Create Table Countries ( | ||
| ID INT AUTO_INCREMENT, | ||
| PRIMARY KEY (ID), | ||
| NAME VARCHAR(50) | ||
| ); | ||
|
|
||
| CREATE TABLE ProductInventory ( | ||
| ID INT, | ||
| ProductName VARCHAR(50), | ||
| WarehouseAmount INT, | ||
| CREATE TABLE Warehouses ( | ||
| ID INT AUTO_INCREMENT, | ||
| PRIMARY KEY (ID), | ||
| WarehouseName VARCHAR(50), | ||
| WarehouseAddress VARCHAR(50), | ||
| WarehouseAddress VARCHAR(50), | ||
| CountryID INT, | ||
| FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION, | ||
| PRIMARY KEY (ID) | ||
| FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION | ||
| ); | ||
|
|
||
| -- 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); | ||
| CREATE TABLE Product ( | ||
| ID INT AUTO_INCREMENT, | ||
| PRIMARY KEY (ID), | ||
| Name VARCHAR(50) | ||
| ); | ||
| CREATE TABLE ProductInventory ( | ||
| ID INT AUTO_INCREMENT, | ||
| PRIMARY KEY (ID), | ||
| Amount INT, | ||
| WarehouseID INT, | ||
| FOREIGN KEY (WarehouseID) REFERENCES Warehouses(ID) ON DELETE NO ACTION, | ||
| ProductId INT, | ||
| FOREIGN KEY (ProductId) REFERENCES Product(ID) ON DELETE CASCADE | ||
| ); | ||
|
|
||
|
|
||
| INSERT INTO Countries (NAME) | ||
| VALUES ('Country1'), ('Country2'); | ||
|
|
||
|
|
||
| INSERT INTO Warehouses (WarehouseName, WarehouseAddress, CountryID) | ||
| VALUES ('Warehouse-1', 'City-1, Street-1', 1), ('Warehouse-2', 'City-2, Street-1', 2); | ||
|
|
||
| INSERT INTO Product (Name) | ||
| VALUES ('Product-1'), ('Product-2'); | ||
|
|
||
| INSERT INTO ProductInventory (WarehouseID, ProductID, Amount) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This Consider populating the inventory with more varied data using the other product and warehouse you created. For example: |
||
| VALUES (1, 1, 2), (2, 2, 5); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the requirements, the script should first delete the
ShopDBdatabase if it already exists. Please addDROP DATABASE IF EXISTS ShopDB;at the very beginning of this file, before theCREATE DATABASEstatement.