Skip to content
Open
Changes from 2 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
35 changes: 35 additions & 0 deletions task.sql
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
# Write your SQL code for the database creation here. Good luck!

create database ShopDB;

use ShopDB;

CREATE TABLE Products (
ID INT PRIMARY KEY AUTO_INCREMENT,
Name VARCHAR(50) NOT NULL,
Description TEXT,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Description uses TEXT (disallowed). Use VARCHAR(100) (or VARCHAR(50)) because only INT, DATE, VARCHAR(50), or VARCHAR(100) are permitted.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Description uses TEXT, which is not allowed. Change it to VARCHAR(100) (or VARCHAR(50)) so the column uses one of the permitted types (INT, DATE, VARCHAR(50), VARCHAR(100)). This addresses checklist item #7 and correction item #13.

Price INT NOT NULL,
WarehouseAmount INT NOT NULL
);

CREATE TABLE Customers (
ID INT PRIMARY KEY AUTO_INCREMENT,
FirstName VARCHAR(50) NOT NULL,
LastName VARCHAR(50) NOT NULL,
Email VARCHAR(100) NOT NULL,
Address TEXT
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Address uses TEXT (disallowed). Use VARCHAR(100) (or VARCHAR(50)) to comply with allowed types.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Address uses TEXT, which is not an allowed type. Replace it with VARCHAR(100) (or VARCHAR(50)) to comply with the permitted types. This addresses checklist item #7 and correction item #13.

);

CREATE TABLE Orders (
ID INT PRIMARY KEY AUTO_INCREMENT,
CustomerID INT NOT NULL,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CustomerID is declared INT NOT NULL but the FK must use ON DELETE SET NULL, so this column must be nullable (remove NOT NULL) to allow it to become NULL on delete.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CustomerID is declared INT NOT NULL but the foreign key uses ON DELETE SET NULL. For that behavior to work the column must be nullable — remove NOT NULL so it is INT. This fixes checklist items #10 and correction items #14/#15.

Date DATE NOT NULL,
FOREIGN KEY (CustomerID) REFERENCES Customers(ID) ON DELETE SET NULL
);

CREATE TABLE OrderItems (
ID INT PRIMARY KEY AUTO_INCREMENT,
OrderID INT,
ProductID INT,
FOREIGN KEY (OrderID) REFERENCES Orders(ID) ON DELETE SET NULL,
FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE SET NULL
);
Loading