-
Notifications
You must be signed in to change notification settings - Fork 0
/
4. TaskDDL2_Fadgham Albar.sql
106 lines (66 loc) · 2 KB
/
4. TaskDDL2_Fadgham Albar.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
CREATE DATABASE IF NOT EXISTS academic;
USE academic;
CREATE TABLE IF NOT EXISTS student_table(
NIM INT NOT NULL,
student_name VARCHAR(255) NOT NULL,
gender VARCHAR(255) NOT NULL,
birth_place VARCHAR(255) NOT NULL,
birth_date DATE,
address VARCHAR(255) NOT NULL,
phone VARCHAR(255) NOT NULL,
PRIMARY KEY (NIM)
) ENGINE=INNODB;
DESC student_table;
CREATE TABLE IF NOT EXISTS lecturer_table(
NIP INT NOT NULL,
lecturer_name VARCHAR(255) NOT NULL,
gender char(1),
laboratory VARCHAR(255) NOT NULL,
interests TEXT,
address VARCHAR(255) NOT NULL,
phone VARCHAR(255) NOT NULL,
PRIMARY KEY (NIP)
) ENGINE=INNODB;
DESC lecturer_table;
ALTER TABLE lecturer_table DROP PRIMARY KEY;
DESC lecturer_table;
ALTER TABLE lecturer_table ADD PRIMARY KEY(NIP);
DESC lecturer_table;
CREATE TABLE IF NOT EXISTS subject_table(
course_code INT NOT NULL,
course_name VARCHAR(255) NOT NULL,
NIP INT NOT NULL,
credits INT NOT NULL,
day VARCHAR(255) NOT NULL,
classroom VARCHAR(255) NOT NULL,
hour DATE,
description TEXT,
PRIMARY KEY (course_code),
FOREIGN KEY (NIP) REFERENCES lecturer_table(NIP)
) ENGINE=INNODB;
DESC subject_table;
CREATE TABLE KRS_table(
KRS_id INT AUTO_INCREMENT,
course_code INT NOT NULL,
NIM INT NOT NULL,
credits INT NOT NULL,
day VARCHAR(255) NOT NULL,
classroom VARCHAR(255) NOT NULL,
year INT NOT NULL,
semester INT NOT NULL,
PRIMARY KEY (KRS_id),
FOREIGN KEY (course_code) REFERENCES subject_table(course_code),
FOREIGN KEY (NIM) REFERENCES student_table(NIM)
) ENGINE=INNODB;
DESC KRS_table;
SHOW tables;
ALTER TABLE lecturer_table RENAME TO professor;
SHOW tables;
ALTER TABLE professor RENAME COLUMN lecturer_name TO professor_name;
DESC professor;
ALTER TABLE student_table ADD mother_name VARCHAR(255) AFTER birth_date;
ALTER TABLE student_table MODIFY gender enum('male','female');
ALTER TABLE student_table MODIFY phone INT;
DESC student_table;
ALTER TABLE subject_table DROP COLUMN description;
DESC subject_table;