From a7de1a000e99bf19f0d96ec1aadda6ec0983e025 Mon Sep 17 00:00:00 2001 From: p1tonidze Date: Wed, 9 Oct 2024 13:36:01 +0300 Subject: [PATCH] Solution --- task.sql | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/task.sql b/task.sql index 0a66d93..084a5a5 100644 --- a/task.sql +++ b/task.sql @@ -1 +1,37 @@ -# Write your SQL code for the database creation here. Good luck! +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(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 +);