-
Notifications
You must be signed in to change notification settings - Fork 0
/
database_create_statement.sql
174 lines (154 loc) · 5.7 KB
/
database_create_statement.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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='TRADITIONAL,ALLOW_INVALID_DATES';
USE `eks0069` ;
drop table if exists `Users`;
drop table if exists `Guests`;
drop table if exists `Hotels`;
drop table if exists `Rooms`;
drop table if exists `RoomTypes`;
drop table if exists `Reservations`;
drop table if exists `Room_Reservation`;
drop table if exists `Location`;
-- -----------------------------------------------------
-- Table `eks0069`.`Location`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `eks0069`.`Location` (
`locationID` INT NOT NULL AUTO_INCREMENT,
`address` VARCHAR(255) NOT NULL,
`city` VARCHAR(45) NOT NULL,
`stateCode` CHAR(2) NOT NULL,
`zip` INT NOT NULL,
PRIMARY KEY (`locationID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `eks0069`.`Hotels`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `eks0069`.`Hotels` (
`hotelID` INT NOT NULL AUTO_INCREMENT,
`FK_locationID` INT NOT NULL,
`hotelName` VARCHAR(20) NOT NULL,
`hotel_URL` VARCHAR(255) NULL DEFAULT NULL,
PRIMARY KEY (`hotelID`, `FK_locationID`),
INDEX `locationID_idx` (`FK_locationID` ASC),
CONSTRAINT `locationID`
FOREIGN KEY (`FK_locationID`)
REFERENCES `eks0069`.`Location` (`locationID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `eks0069`.`Guests`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `eks0069`.`Guests` (
`guestID` INT NOT NULL AUTO_INCREMENT,
`fName` CHAR(20) NOT NULL,
`lName` CHAR(20) NOT NULL,
`address1` CHAR(45) NOT NULL,
`address2` CHAR(45) NULL DEFAULT NULL,
`city` CHAR(20) NOT NULL,
`stateCode` CHAR(2) NOT NULL,
`postCode` CHAR(20) NOT NULL,
`phone` CHAR(10) DEFAULT NULL,
`email` CHAR(50) NOT NULL UNIQUE,
PRIMARY KEY (`guestID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `eks0069`.`Users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `eks0069`.`Users` (
`userID` INT NOT NULL AUTO_INCREMENT,
`uName` CHAR(64) NOT NULL UNIQUE,
`pass` CHAR(255) NOT NULL,
`address1` CHAR(100) NOT NULL,
`address2` CHAR(100) NULL,
`city` CHAR(20) NOT NULL,
`stateCode` CHAR(2) NOT NULL,
`phone` CHAR(10) NULL,
`fName` CHAR(20) NOT NULL,
`lName` CHAR(20) NOT NULL,
`salt` CHAR(64) NOT NULL,
`email` CHAR(50) NOT NULL UNIQUE,
`isAdmin` BOOLEAN DEFAULT 0,
PRIMARY KEY (`userID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `eks0069`.`Reservations`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `eks0069`.`Reservations` (
`reservationID` INT NOT NULL AUTO_INCREMENT,
`FK_guestID` INT NULL,
`FK_userID` INT NULL,
`checkinDate` DATE NULL DEFAULT NULL,
`checkoutDate` DATE NULL DEFAULT NULL,
`totalPrice` DECIMAL(10,2) NULL DEFAULT NULL,
PRIMARY KEY (`reservationID`),
INDEX `guestID_idx` (`FK_guestID` ASC),
INDEX `userID_idx` (`FK_userID` ASC),
CONSTRAINT `guestID`
FOREIGN KEY (`FK_guestID`)
REFERENCES `eks0069`.`Guests` (`guestID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `userID`
FOREIGN KEY (`FK_userID`)
REFERENCES `eks0069`.`Users` (`userID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `eks0069`.`RoomTypes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `eks0069`.`RoomTypes` (
`roomTypeID` INT NOT NULL AUTO_INCREMENT,
`roomPrice` DECIMAL(10,2) NOT NULL,
`roomDesc` VARCHAR(255) NULL DEFAULT NULL,
`isSmoking` TINYINT(1) NOT NULL DEFAULT FALSE,
`maxGuests` INT NULL,
PRIMARY KEY (`roomTypeID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `eks0069`.`Rooms`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `eks0069`.`Rooms` (
`roomID` INT NOT NULL AUTO_INCREMENT,
`FK_roomTypeID` INT NOT NULL,
`FK_hotelID` INT NOT NULL,
`isBooked` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`roomID`),
INDEX `hotelID_idx` (`FK_hotelID` ASC),
INDEX `roomTypeID_idx` (`FK_roomTypeID` ASC),
CONSTRAINT `roomTypeID`
FOREIGN KEY (`FK_roomTypeID`)
REFERENCES `eks0069`.`RoomTypes` (`roomTypeID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `hotelID`
FOREIGN KEY (`FK_hotelID`)
REFERENCES `eks0069`.`Hotels` (`hotelID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `eks0069`.`Room_Reservation`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `eks0069`.`Room_Reservation` (
`FK_roomID` INT NOT NULL,
`FK_reservationID` INT NOT NULL,
INDEX `reservationID_idx` (`FK_reservationID` ASC),
INDEX `roomId_idx` (`FK_roomID` ASC),
PRIMARY KEY (`FK_reservationID`, `FK_roomID`),
CONSTRAINT `roomId`
FOREIGN KEY (`FK_roomID`)
REFERENCES `eks0069`.`Rooms` (`roomID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `reservationID`
FOREIGN KEY (`FK_reservationID`)
REFERENCES `eks0069`.`Reservations` (`reservationID`)
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;