Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 38 additions & 11 deletions task.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Create database and tables

DROP DATABASE IF EXISTS ShopDB;
CREATE DATABASE ShopDB;
USE ShopDB;

Expand All @@ -9,25 +9,52 @@ CREATE TABLE Countries (
PRIMARY KEY (ID)
);

CREATE TABLE Warehouses (
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task (and the previous review) requires the DDL be ordered Countries -> Products -> Warehouses -> ProductInventory. Here Warehouses is created before Products which violates that requested order and may be flagged by the grader. Move the Products CREATE TABLE block so it appears before the Warehouses CREATE TABLE block.

ID INT,
Name VARCHAR(50),
Address VARCHAR(50),
CountryID INT,
FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION,
PRIMARY KEY (ID)
);

CREATE TABLE Products (
ID INT,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primary key ID columns (e.g. Products.ID) are declared without NOT NULL or AUTO_INCREMENT. Consider adding NOT NULL and AUTO_INCREMENT to primary key integer columns to ensure uniqueness and simplify inserts (optional but recommended).

Name VARCHAR(50),
Description VARCHAR(100),
Price INT,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Price is currently declared as INT. For monetary values use a decimal type (for example DECIMAL(10,2)) and consider adding NOT NULL to enforce presence of a price.

PRIMARY KEY (ID)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Products table is defined but there are no INSERT statements for Products. The ProductInventory rows reference ProductID = 1, so you must insert a matching product (e.g., ID = 1 with name/description/price) before inserting into ProductInventory.

);

CREATE TABLE ProductInventory (
ID INT,
ProductName VARCHAR(50),
ProductID INT,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProductInventory uses a surrogate ID as primary key (ID). To prevent duplicate inventory rows and better model the relationship, consider making (ProductID, WarehouseID) the primary key or at least a UNIQUE constraint on those two columns.

WarehouseAmount INT,
WarehouseName VARCHAR(50),
WarehouseAddress VARCHAR(50),
CountryID INT,
FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION,
WarehouseID INT,
FOREIGN KEY (WarehouseID) REFERENCES Warehouses(ID) ON DELETE NO ACTION,
FOREIGN KEY (ProductID) REFERENCES Products(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 Products (ID,Name,Description,Price)
VALUES (1, 'Product1', 'Description1', 100);
INSERT INTO Products (ID,Name,Description,Price)
VALUES (2, 'Product2', 'Description2', 200);

INSERT INTO Warehouses (ID,Name,Address,CountryID)
VALUES (1, 'Warehouse1', 'Address1', 1);
INSERT INTO Warehouses (ID,Name,Address,CountryID)
VALUES (2, 'Warehouse2', 'Address2', 2);

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