-
Notifications
You must be signed in to change notification settings - Fork 156
DB Normalised #163
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?
DB Normalised #163
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -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) | ||
| ); | ||
|
|
||
| CREATE TABLE Warehouses ( | ||
|
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. 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, | ||
|
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. 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, | ||
|
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. 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, | ||
|
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. 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) | ||
|
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. 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); | ||
|
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. 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). |
||
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.
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.