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
30 changes: 29 additions & 1 deletion task.sql
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
# Write your SQL code for the database creation here. Good luck!
create database 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.

Replace this line with the required construction CREATE DATABASE IF NOT EXISTS ShopDB; so the database is created idempotently and appears immediately before USE ShopDB; as required by the task.

USE ShopDB;
CREATE TABLE Products(
ID INT PRIMARY KEY AUTO_INCREMENT,
Name VARCHAR(50),
Description VARCHAR(100),
Price INT,
WarehouseAmount INT
);
CREATE TABLE Customers(
ID INT PRIMARY KEY AUTO_INCREMENT,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Email VARCHAR(50),
Address VARCHAR(100)
);
CREATE TABLE Orders(
ID INT PRIMARY KEY AUTO_INCREMENT,
CustomerID INT,
Date DATE,
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