Skip to content
Open
Changes from all 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
9 changes: 7 additions & 2 deletions task.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
-- Use our database
USE ShopDB;

-- Some data should be created outside the transaction (here)
INSERT INTO Orders (CustomerID, Date) VALUES (1, '2023-01-01');
SET @order_id = LAST_INSERT_ID();

-- Start the transaction
START TRANSACTION;

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 transaction currently protects only the UPDATE Products. The requirement says creating an OrderItem and updating WarehouseAmount should be tied together; consider starting the transaction before inserting into Orders/OrderItems so they are all committed or rolled back together.


-- And some data should be created inside the transaction
INSERT INTO OrderItems (OrderID, ProductID, Count)
VALUES (@order_id, 1, 1);
Comment on lines +10 to +11

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here the quantity is hard-coded as 1, but you also separately set @qty = 1 below; per checklist item #19, consider defining @qty once before this INSERT and using @qty here so the order item count and stock update always stay in sync if the quantity changes.

SET @qty = 1;
UPDATE Products SET WarehouseAmount = WarehouseAmount - @qty
Comment on lines +12 to +13

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Because the quantity is hard-coded here and also assigned separately in SET @qty = 1, there is a risk they diverge if one is changed; instead, set @qty once and use it in both the INSERT and this UPDATE to derive the quantity from a single source (checklist item #19).

WHERE ID = 1;

COMMIT;
Loading