Skip to content
Open
Changes from 1 commit
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(255) 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.

Name uses VARCHAR(255) which is not allowed. Use VARCHAR(50) or VARCHAR(100) as required by the task.

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 DECIMAL(10, 2) 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.

Price is DECIMAL(10, 2) which is not in the allowed types. Change to an allowed type (for example INT) per the task constraints.

WarehouseAmount INT NOT NULL
);

CREATE TABLE Customers (
ID INT PRIMARY KEY AUTO_INCREMENT,
FirstName VARCHAR(255) 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.

FirstName uses VARCHAR(255) (disallowed). Use VARCHAR(50) or VARCHAR(100) instead.

LastName VARCHAR(255) 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.

LastName uses VARCHAR(255) (disallowed). Use VARCHAR(50) or VARCHAR(100) instead.

Email VARCHAR(255) 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.

Email uses VARCHAR(255) (disallowed). Use VARCHAR(50) or VARCHAR(100) instead.

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)
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 foreign key for CustomerID is missing ON DELETE SET NULL. Use the exact construction: FOREIGN KEY (CustomerID) REFERENCES Customers(ID) ON DELETE SET NULL as required by the task.

);

CREATE TABLE OrderItems (
ID INT PRIMARY KEY AUTO_INCREMENT,
OrderID 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.

OrderID is declared INT NOT NULL but if you use ON DELETE SET NULL on its FK it must be nullable. Remove NOT NULL to allow setting it to NULL on delete.

ProductID 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.

ProductID is declared INT NOT NULL but if you use ON DELETE SET NULL on its FK it must be nullable. Remove NOT NULL to allow setting it to NULL on delete.

FOREIGN KEY (OrderID) REFERENCES Orders(ID),
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 foreign key on OrderID is missing ON DELETE SET NULL. Change to FOREIGN KEY (OrderID) REFERENCES Orders(ID) ON DELETE SET NULL.

FOREIGN KEY (ProductID) REFERENCES Products(ID)
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 foreign key on ProductID is missing ON DELETE SET NULL. Change to FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE SET NULL.

);