-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLittleLemonSQLScript.txt
142 lines (124 loc) · 4.99 KB
/
LittleLemonSQLScript.txt
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
-- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
-- -----------------------------------------------------
-- Schema LittleLemonDB
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema LittleLemonDB
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `LittleLemonDB` DEFAULT CHARACTER SET utf8 ;
USE `LittleLemonDB` ;
-- -----------------------------------------------------
-- Table `LittleLemonDB`.`Customer`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `LittleLemonDB`.`Customer` (
`CustomerID` INT NOT NULL AUTO_INCREMENT,
`CustomerName` VARCHAR(255) NOT NULL,
`PhoneNumber` VARCHAR(11) NOT NULL,
`Email` VARCHAR(255) NULL,
PRIMARY KEY (`CustomerID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `LittleLemonDB`.`Staff`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `LittleLemonDB`.`Staff` (
`StaffID` INT NOT NULL AUTO_INCREMENT,
`StaffName` VARCHAR(255) NOT NULL,
`Role` VARCHAR(255) NOT NULL,
`Salary` INT NOT NULL,
PRIMARY KEY (`StaffID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `LittleLemonDB`.`Booking`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `LittleLemonDB`.`Booking` (
`BookingID` INT NOT NULL AUTO_INCREMENT,
`BookingDate` DATETIME NOT NULL,
`TableNumber` INT NULL,
`CustomerID` INT NOT NULL,
`StaffID` INT NOT NULL,
PRIMARY KEY (`BookingID`),
INDEX `fk_Booking_Customer1_idx` (`CustomerID` ASC) VISIBLE,
INDEX `fk_Booking_Staff1_idx` (`StaffID` ASC) VISIBLE,
CONSTRAINT `fk_Booking_Customer1`
FOREIGN KEY (`CustomerID`)
REFERENCES `LittleLemonDB`.`Customer` (`CustomerID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Booking_Staff1`
FOREIGN KEY (`StaffID`)
REFERENCES `LittleLemonDB`.`Staff` (`StaffID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `LittleLemonDB`.`OrderStatus`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `LittleLemonDB`.`OrderStatus` (
`StatusID` INT NOT NULL AUTO_INCREMENT,
`DeliveryDate` DATETIME NOT NULL,
`Status` ENUM('In Queue', 'Preparing', 'En Route', 'Delivered') NOT NULL,
`OrderID` INT NOT NULL,
PRIMARY KEY (`StatusID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `LittleLemonDB`.`Menu`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `LittleLemonDB`.`Menu` (
`MenuID` INT NOT NULL AUTO_INCREMENT,
`Cuisine` ENUM('Italian', 'French', 'Greek', 'Turkish', 'American') NOT NULL,
PRIMARY KEY (`MenuID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `LittleLemonDB`.`MenuItem`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `LittleLemonDB`.`MenuItem` (
`ItemID` INT NOT NULL AUTO_INCREMENT,
`ItemType` ENUM('Drink', 'Starter', 'Entree', 'Dessert') NULL,
`Price` DECIMAL(10,2) NOT NULL,
`ItemName` VARCHAR(255) NOT NULL,
`MenuID` INT NOT NULL,
PRIMARY KEY (`ItemID`),
INDEX `fk_MenuItemID_Menu1_idx` (`MenuID` ASC) VISIBLE,
CONSTRAINT `fk_MenuItemID_Menu1`
FOREIGN KEY (`MenuID`)
REFERENCES `LittleLemonDB`.`Menu` (`MenuID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `LittleLemonDB`.`ItemOrder`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `LittleLemonDB`.`ItemOrder` (
`OrderID` INT NOT NULL AUTO_INCREMENT,
`BookingID` INT NOT NULL,
`OrderDate` DATETIME NOT NULL,
`Quantity` INT NOT NULL,
`TotalCost` DECIMAL(10,2) NOT NULL,
`OrderStatusID` INT NOT NULL,
`MenuItemID` INT NOT NULL,
PRIMARY KEY (`OrderID`),
INDEX `BookingID_idx` (`BookingID` ASC) VISIBLE,
INDEX `fk_Order_OrderStatus1_idx` (`OrderStatusID` ASC) VISIBLE,
INDEX `fk_Order_MenuItemID1_idx` (`MenuItemID` ASC) VISIBLE,
CONSTRAINT `BookingID`
FOREIGN KEY (`BookingID`)
REFERENCES `LittleLemonDB`.`Booking` (`BookingID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Order_OrderStatus1`
FOREIGN KEY (`OrderStatusID`)
REFERENCES `LittleLemonDB`.`OrderStatus` (`StatusID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Order_MenuItemID1`
FOREIGN KEY (`MenuItemID`)
REFERENCES `LittleLemonDB`.`MenuItem` (`ItemID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;