Skip to content
Open
Changes from 1 commit
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
31 changes: 23 additions & 8 deletions task.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,38 @@ CREATE TABLE Countries (

CREATE TABLE ProductInventory (
ID INT,
ProductName VARCHAR(50),
ProductID INT,
WarehouseAmount INT,
WarehouseName VARCHAR(50),
WarehouseAddress VARCHAR(50),
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)
);

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 script is missing a DROP DATABASE ShopDB; statement before creating the database (the task explicitly asks to remove any existing ShopDB using DROP DATABASE ShopDB;). Add this at the top before CREATE DATABASE to match the requirements.

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,
FOREIGN KEY (CountryID) REFERENCES Countries(ID) ON DELETE NO ACTION,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warehouses table exists but there are no INSERT statements for Warehouses. ProductInventory references WarehouseID = 1 and 2, so add INSERTs for warehouses with IDs 1 and 2 (including Address and CountryID matching the Countries rows) before inserting product inventory.

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.

);
-- 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 ProductInventory (ID,ProductID,WarehouseAmount,WarehouseID)
VALUES (1, 1, 2, 1);
INSERT INTO ProductInventory (ID,ProductID,WarehouseAmount,WarehouseID)
VALUES (2, 1, 5, 2);
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 two INSERT INTO ProductInventory (...) VALUES (...) statements will fail due to missing referenced Products and Warehouses rows. Ensure referenced Products and Warehouses are inserted first (or insert ProductInventory after those INSERTs). Also confirm the inserted warehouse CountryID values reference existing Countries (IDs 1 and 2).

Loading