-
Notifications
You must be signed in to change notification settings - Fork 180
Edit task.sql #191
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?
Edit task.sql #191
Changes from all commits
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 |
|---|---|---|
| @@ -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; | ||
|
|
||
| -- 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
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. Here the quantity is hard-coded as |
||
| SET @qty = 1; | ||
| UPDATE Products SET WarehouseAmount = WarehouseAmount - @qty | ||
|
Comment on lines
+12
to
+13
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. Because the quantity is hard-coded here and also assigned separately in |
||
| WHERE ID = 1; | ||
|
|
||
| COMMIT; | ||
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 transaction currently protects only the
UPDATE Products. The requirement says creating anOrderItemand updatingWarehouseAmountshould be tied together; consider starting the transaction before inserting intoOrders/OrderItemsso they are all committed or rolled back together.