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
40 changes: 39 additions & 1 deletion task.sql
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
# Write your SQL code for the database creation here. Good luck!
CREATE DATABASE ShopDB;
USE ShopDB;
/*
Creating tables for ShopDB database
*/
CREATE TABLE Products (
ID INT AUTO_INCREMENT,
NAME VARCHAR(100),
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 requirement specifies this column should be named Name. While SQL is often case-insensitive for identifiers, it's best practice to match the naming in the requirements exactly to ensure portability and consistency.

Description VARCHAR(100),
Price INT,
WarehouseAmount INT,
PRIMARY KEY (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.

This CREATE TABLE statement has some syntax errors that are repeated in the other tables. Remember to separate all column and constraint definitions with commas, and to end the entire statement with a semicolon (;).


CREATE TABLE Customers (
ID INT AUTO_INCREMENT,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Email VARCHAR(50),
Address VARCHAR(100),
PRIMARY KEY (ID)
);

CREATE TABLE Orders (
ID INT AUTO_INCREMENT,
CustomerID INT,
Date DATE,
PRIMARY KEY (ID),
FOREIGN KEY (CustomerID) REFERENCES Customers(ID) ON DELETE SET NULL
);

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