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
50 changes: 49 additions & 1 deletion task.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,58 @@
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.

Move USE ShopDB AFTER the DROP/CREATE DATABASE statements, or remove this initial USE since there's no ShopDB to use yet at this point.


-- Some data should be created outside the transaction (here)
DROP DATABASE 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)
Comment on lines +9 to +42

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Replace all manual CREATE TABLE statements (lines 9-42) with the create-database.sql script from the repository as required by the task description. Use: source create-database.sql or @create-database.sql instead of recreating tables.

Comment on lines +9 to +42

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Lines 9-42 contain manual CREATE TABLE statements instead of using the repository script. Replace the entire CREATE TABLE block (lines 9-42) with source create-database.sql or @create-database.sql as required by the task requirements.

);

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');

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 (LAST_INSERT_ID(), 1, 1);
UPDATE Products SET WarehouseAmount = WarehouseAmount - 1 WHERE ID = 1;

COMMIT;
Loading