forked from mate-academy/rda_task_3_transactions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-database.sql
44 lines (38 loc) · 1.05 KB
/
create-database.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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(50),
PRIMARY KEY (ID)
);
CREATE TABLE Orders (
ID INT AUTO_INCREMENT,
CustomerID INT,
FOREIGN KEY (CustomerID) REFERENCES Customers(ID) ON DELETE SET NULL,
Date DATE,
PRIMARY KEY (ID)
);
CREATE TABLE OrderItems (
ID INT AUTO_INCREMENT,
OrderID INT,
FOREIGN KEY (OrderID) REFERENCES Orders(ID) ON DELETE SET NULL,
ProductID INT,
Count INT,
FOREIGN KEY (ProductID) REFERENCES Products(ID) ON DELETE SET NULL,
PRIMARY KEY (ID)
);
INSERT INTO Products (Name, Description, Price, WarehouseAmount)
VALUES ('AwersomeProduct', 'Product Desctiption', 5, 42);
INSERT INTO Customers (FirstName, LastName, Email, Address)
VALUES ('John', 'Dou', '[email protected]', 'far, far away');