-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasic SQL_Constraints.sql
More file actions
40 lines (34 loc) · 1.06 KB
/
Basic SQL_Constraints.sql
File metadata and controls
40 lines (34 loc) · 1.06 KB
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
/*
Constraints digunakan untuk menetapkan aturan terhadap data dalam tabel,
seperti memastikan data tidak boleh kosong, harus unik, atau sebagai pengenal utama (primary key).
- NOT NULL
- UNIQUE
- PRIMARY KEY : secara otomatis menggabungkan dua aturan penting:
tidak boleh kosong (seperti NOT NULL) dan tidak boleh ada duplikat (seperti UNIQUE).
- INDEX
*/
CREATE TABLE info_bus (
kode_bus char (6) NOTNULL,
nama_sopir char (10) NOTNULL,
terakhir_dilihat char (6) NOTNULL,
warna_bus char (6) NOTNULL,
aktivitas_bus char (6) NOTNULL
);
CREATE TABLE info_bus (
kode_bus char (6) UNIQUE,
nama_sopir char (10) NOTNULL,
terakhir_dilihat char (6) NOTNULL,
warna_bus char (6) NOTNULL,
aktivitas_bus char (6) NOTNULL,
PRIMARY KEY (kode_bus)
);
CREATE TABLE info_bus (
kode_bus char (6) UNIQUE PRIMARY KEY,
nama_sopir char (10) NOTNULL PRIMARY KEY,
terakhir_dilihat char (6) NOTNULL,
warna_bus char (6) NOTNULL,
aktivitas_bus char (6) NOTNULL,
PRIMARY KEY (kode_bus)
);
CREATE INDEX info_bus_terakhir_dilihat_idx
ON info_bus (terakhir_dilihat);