-
Notifications
You must be signed in to change notification settings - Fork 0
/
schemas.sql
56 lines (44 loc) · 1.19 KB
/
schemas.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
DROP DATABASE IF EXISTS uts_visual_programming;
CREATE DATABASE uts_visual_programming;
USE uts_visual_programming;
CREATE TABLE rooms (
_ INT AUTO_INCREMENT PRIMARY KEY,
room_code VARCHAR(64) UNIQUE,
room_name VARCHAR(128),
room_location VARCHAR(128),
room_wide INT,
room_capacity INT,
room_price BIGINT,
room_note TEXT
);
CREATE INDEX idx_room_code
ON rooms (room_code);
CREATE INDEX idx_room_name
ON rooms (room_name);
CREATE INDEX idx_room_location
ON rooms (room_location);
CREATE INDEX idx_room_wide
ON rooms (room_wide);
CREATE INDEX idx_room_capacity
ON rooms (room_capacity);
CREATE INDEX idx_room_price
ON rooms (room_price);
CREATE INDEX idx_room_note
ON rooms (room_note);
DELIMITER //
CREATE TRIGGER set_room_code BEFORE INSERT ON rooms
FOR EACH ROW
BEGIN
DECLARE next_id INT;
SELECT COALESCE(MAX(_) + 1, 1) INTO next_id FROM rooms;
SET NEW.room_code = CONCAT('ROOM-', next_id);
END;
//
DELIMITER ;
INSERT INTO rooms (
room_name, room_location, room_wide,
room_capacity, room_price, room_note
) VALUES (
'Super Deluxe', 'Lantai 1, Nomor 101', 10,
3, 784000, 'Peraturan khusus berlaku'
);