-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_tables.sql
49 lines (38 loc) · 1.16 KB
/
create_tables.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
/*
CSC 365 LAB 7
Create And Populate Inn Tables
Grant user priviledges
*/
USE DBNAME;
// create tables
CREATE TABLE IF NOT EXISTS lab7_rooms (
RoomCode char(5) PRIMARY KEY,
RoomName varchar(30) NOT NULL,
Beds int(11) NOT NULL,
bedType varchar(8) NOT NULL,
maxOcc int(11) NOT NULL,
basePrice DECIMAL(6,2) NOT NULL,
decor varchar(20) NOT NULL,
UNIQUE (RoomName)
);
CREATE TABLE IF NOT EXISTS lab7_reservations (
CODE int(11) PRIMARY KEY,
Room char(5) NOT NULL,
CheckIn date NOT NULL,
Checkout date NOT NULL,
Rate DECIMAL(6,2) NOT NULL,
LastName varchar(15) NOT NULL,
FirstName varchar(15) NOT NULL,
Adults int(11) NOT NULL,
Kids int(11) NOT NULL,
UNIQUE (Room, CheckIn),
UNIQUE (Room, Checkout),
FOREIGN KEY (Room) REFERENCES lab7_rooms (RoomCode)
);
// populate tables
INSERT INTO lab7_rooms SELECT * FROM INN.rooms;
INSERT INTO lab7_reservations SELECT CODE, Room,
DATE_ADD(CheckIn, INTERVAL 9 YEAR),
DATE_ADD(Checkout, INTERVAL 9 YEAR),
Rate, LastName, FirstName, Adults, Kids FROM INN.reservations;
// grant priviledges