Solution#122
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job starting the database normalization process! You've correctly identified the need for new tables like Products and Warehouses. However, the current SQL script has a few critical issues that prevent it from running successfully.
To get it working, please address the following:
- Missing Semicolon: The script fails immediately because of a missing semicolon at the end of the
DROP DATABASEstatement on line 2. - Missing
WarehousesTable: YourProductInventorytable and anINSERTstatement both reference aWarehousestable, but theCREATE TABLEstatement for it is missing from the script. - Duplicate Table Definition: The
ProductInventorytable is defined twice (starting on line 12 and line 26). Please remove the first, unnormalized definition. - Incorrect Column Name: The final
INSERTstatement (line 43) uses the column nameAmount, but your newProductInventorytable definition usesWarehouseAmount. These need to match.
Once these items are fixed, your normalized database schema should work as intended. Keep up the great work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| @@ -1,5 +1,5 @@ | |||
| -- Create database and tables | |||
|
|
|||
| DROP DATABASE IF EXISTS ShopDB; | |||
There was a problem hiding this comment.
It's a good practice to end every SQL statement with a semicolon. This line is missing one.
| CREATE TABLE ProductInventory ( | ||
| ID INT AUTO_INCREMENT, | ||
| ProductID INT NOT NULL, | ||
| WarehouseID INT NOT NULL, | ||
| WarehouseAmount INT NOT NULL, | ||
| PRIMARY KEY (ID), | ||
| FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE CASCADE, | ||
| FOREIGN KEY (WarehouseID) REFERENCES Warehouses(ID) ON DELETE CASCADE | ||
| ); |
There was a problem hiding this comment.
This ProductInventory table definition is a good step towards normalization! However, it has a dependency on a Warehouses table (see the foreign key on line 36), which is never created in this script. As part of normalizing the database to the third normal form, you need to extract warehouse information (WarehouseName, WarehouseAddress) into its own Warehouses table and create it here.
| INSERT INTO Warehouses (Name, Address, CountryID) | ||
| VALUES ('Warehouse-1', 'City-1, Street-1', 1), ('Warehouse-2', 'City-2, Street-2', 2); |
There was a problem hiding this comment.
This INSERT statement will fail because the Warehouses table it's trying to add data to has not been created. You'll need to add a CREATE TABLE Warehouses statement before this line for the script to work.
| INSERT INTO ProductInventory (ProductID, WarehouseID, Amount) | ||
| VALUES (1, 1, 2), (1, 2, 5); |
There was a problem hiding this comment.
There's a small mismatch here that will cause an error. The INSERT statement refers to a column named Amount, but in your new ProductInventory table definition on line 33, the column is named WarehouseAmount. These names need to match for the query to succeed.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work on this submission! You've successfully addressed all the feedback from the previous review, and your task.sql script now fully meets all requirements. The database schema is correctly normalized to the Third Normal Form, with all tables and constraints created properly. The test data is also inserted correctly into the new structure. Your script is clean, logical, and ready to go. Great job!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.