Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions create-database.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CREATE DATABASE ShopDB;
USE ShopDB;


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 comment indicates some data should be created outside the transaction, but all operations here need to be atomic. Either update the comment to explain why everything is in the transaction, or clarify what data the original author intended to place outside.

CREATE TABLE Products (
ID INT AUTO_INCREMENT,
Name VARCHAR(50),
Expand Down
6 changes: 3 additions & 3 deletions task.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ USE ShopDB;
-- Some data should be created outside the transaction (here)

-- Start the transaction
INSERT INTO Orders (CustomerID, Date) VALUES (1, '2023-01-01');
START TRANSACTION;

-- And some data should be created inside the transaction

INSERT INTO OrderItems (OrderID, ProductID, Count) VALUES (1, 1, 1);
UPDATE Products SET WarehouseAmount = WarehouseAmount - 1 WHERE ID = 1;
COMMIT;
Loading