Skip to content

Solution#163

Open
NazarKulyk6 wants to merge 1 commit into
mate-academy:mainfrom
NazarKulyk6:main
Open

Solution#163
NazarKulyk6 wants to merge 1 commit into
mate-academy:mainfrom
NazarKulyk6:main

Conversation

@NazarKulyk6
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

Great work on this task! I am approving your solution as it correctly fulfills all the requirements. You've done an excellent job using a transaction to ensure data consistency when adding the order item and updating the product stock, which was a key part of this exercise.

For future reference, I'd suggest avoiding hardcoded IDs like OrderID = 1. While it works for this specific scenario, it makes the script less robust because it would fail or update the wrong order if the Orders table already had data. A better practice is to get the ID of the new order dynamically. For example, in MySQL you could use LAST_INSERT_ID() and a variable to pass the value to the next statement:

-- After inserting into Orders
SET @last_order_id = LAST_INSERT_ID();

-- Use the variable when inserting into OrderItems
INSERT INTO OrderItems (OrderID, ProductID, Count) VALUES (@last_order_id, 1, 1);

This is just a suggestion for improvement, as your current code does pass all the requirements. Keep up the great work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Comment thread task.sql
Comment on lines +15 to +16
INSERT INTO OrderItems (OrderID, ProductID, Count)
VALUES (1, 1, 1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good use of a transaction to ensure atomicity. However, hardcoding OrderID = 1 makes the script brittle; it will only work as expected if the Orders table is empty when the script runs. A more robust approach is to dynamically retrieve the ID of the order you created on line 7. Consider using MySQL's LAST_INSERT_ID() function to get this value and use it in your INSERT statement here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants