From a00efc4ab2005002b2cb9692e84b6fb2e8984bc7 Mon Sep 17 00:00:00 2001 From: Vitalii Vodolazkyi Date: Fri, 22 May 2026 11:19:00 +0200 Subject: [PATCH 1/3] created order and transaction with product update --- task.sql | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/task.sql b/task.sql index 8adf22b..caa00e4 100644 --- a/task.sql +++ b/task.sql @@ -2,10 +2,16 @@ USE ShopDB; -- Some data should be created outside the transaction (here) - +INSERT INTO Orders (CustomerID, Date) +VALUES (1, '2023-01-01'); -- Start the transaction 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; \ No newline at end of file From 3b4fd5855a7672f1b28d3eb4301bd89dbce94733 Mon Sep 17 00:00:00 2001 From: Vitalii Vodolazkyi Date: Fri, 22 May 2026 11:19:42 +0200 Subject: [PATCH 2/3] created order and transaction with product update --- task.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task.sql b/task.sql index caa00e4..15de7c9 100644 --- a/task.sql +++ b/task.sql @@ -14,4 +14,4 @@ VALUES (1, 1, 1); UPDATE Products SET WarehouseAmount = WarehouseAmount - 1 WHERE ID = 1; -COMMIT; \ No newline at end of file +COMMIT; \ No newline at end of file From 833f1e389df1434cf6092e30897b5d15f2faebd7 Mon Sep 17 00:00:00 2001 From: Vitalii Vodolazkyi Date: Fri, 22 May 2026 11:24:56 +0200 Subject: [PATCH 3/3] recreate database and tables afre rewiew --- task.sql | 57 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/task.sql b/task.sql index 15de7c9..f4d1a69 100644 --- a/task.sql +++ b/task.sql @@ -1,15 +1,58 @@ --- Use our database -USE ShopDB; +DROP DATABASE IF EXISTS ShopDB; +CREATE DATABASE ShopDB; +USE ShopDB; + +CREATE TABLE Products ( + ID INT AUTO_INCREMENT, + Name VARCHAR(50), + Description VARCHAR(100), + Price INT, + WarehouseAmount INT, + PRIMARY KEY (ID) +); + +CREATE TABLE Customers ( + ID INT AUTO_INCREMENT, + FirstName VARCHAR(50), + LastName VARCHAR(50), + Email VARCHAR(50), + Address VARCHAR(50), + PRIMARY KEY (ID) +); + +CREATE TABLE Orders ( + ID INT AUTO_INCREMENT, + CustomerID INT, + FOREIGN KEY (CustomerID) REFERENCES Customers(ID) ON DELETE SET NULL, + Date DATE, + PRIMARY KEY (ID) +); + +CREATE TABLE OrderItems ( + ID INT AUTO_INCREMENT, + OrderID INT, + FOREIGN KEY (OrderID) REFERENCES Orders(ID) ON DELETE SET NULL, + ProductID INT, + Count INT, + FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE SET NULL, + PRIMARY KEY (ID) +); + +INSERT INTO Products (Name, Description, Price, WarehouseAmount) +VALUES ('AwersomeProduct', 'Product Desctiption', 5, 42); + +INSERT INTO Customers (FirstName, LastName, Email, Address) +VALUES ('John', 'Dou', 'j@dou.ua', 'far, far away'); --- Some data should be created outside the transaction (here) INSERT INTO Orders (CustomerID, Date) VALUES (1, '2023-01-01'); --- Start the transaction -START TRANSACTION; --- And some data should be created inside the transaction +SET @OrderID = LAST_INSERT_ID(); + +START TRANSACTION; + INSERT INTO OrderItems (OrderID, ProductID, Count) -VALUES (1, 1, 1); +VALUES (@OrderID, 1, 1); UPDATE Products SET WarehouseAmount = WarehouseAmount - 1 WHERE ID = 1;