Projek UAS Database
Projek UAS Database
DISUSUN OLEH
BAB 1
1.1 Latar Belakang
1.2Tujuan
BAB 2
2.1 Perancangan Konseptual
2.2 Perancangan Logikal
2.3 Perancangan Fisikal
2.4 Script SQL
Perancangan Conceptual:
Step 1.1 Identify Entity Types:
a. Student
b. Teacher
c. Course
d. Classroom
e. Department
a. Student:
a. StudentID - Integer
b. TeacherID - Integer
c. CourseID - Integer
d. RoomNumber - String
e. DepartmentID - Integer
f. Name - String
g. DateOfBirth - Date
h. Address - String
i. Grade - String
j. SubjectSpecialization - String
k. CourseName - String
l. CreditHours - Integer
m. DepartmentName - String
n. Capacity - Integer
a. Candidate Keys:
Student: {StudentID}
Teacher: {TeacherID}
Course: {CourseID}
Classroom: {RoomNumber}
Department: {DepartmentID}
b. Primary Keys:
Student: {StudentID}
Teacher: {TeacherID}
Course: {CourseID}
Classroom: {RoomNumber}
Department: {DepartmentID}
Perancangan logical
Step 2.1 Derive Relations for Logical Data Model:
a. Student (StudentID, Name, DateOfBirth, Address, Grade)
b. Teacher (TeacherID, Name, SubjectSpecialization, DateOfBirth, Address)
c. Course (CourseID, CourseName, CreditHours, DepartmentID)
d. Classroom (RoomNumber, Capacity)
e. Department (DepartmentID, DepartmentName)
f. Enroll (StudentID, CourseID)
g. Teach (TeacherID, CourseID)
h. Belong (StudentID, DepartmentID)
i. Allocate (RoomNumber, CourseID)
Conclusion:
All relations are either in 1NF, 2NF, or 3NF.
No further normalization is required for the given relations.
Transaction: Insert a record into the Enroll table with the StudentID and
CourseID.
Validation: Check that both StudentID and CourseID exist in the Student and
Course tables, respectively.
Transaction: Insert a record into the Teach table with the TeacherID and
CourseID.
Validation: Verify that both TeacherID and CourseID exist in the Teacher and
Course tables, respectively.
Transaction: Insert a record into the Belong table with the StudentID and
DepartmentID.
Validation: Ensure that both StudentID and DepartmentID exist in the Student
and Department tables, respectively.
Transaction: Insert a record into the Allocate table with the RoomNumber and
CourseID.
Validation: Check that both RoomNumber and CourseID exist in the Classroom
and Course tables, respectively.
Transaction: Insert a record into the Student table with StudentID, Name,
DateOfBirth, Address, and Grade.
Validation: Ensure that StudentID is unique and other attributes meet any
constraints.
7. Delete a Course:
Transaction: Delete a record from the Course table for a specific CourseID.
Validation: Ensure that the CourseID exists and that cascading actions (if
defined) do not violate referential integrity.
Grade: Must be a valid value within the defined range (e.g., A-F, numerical
scale, etc.)
CreditHours: Must be a positive integer value
DateOfBirth: Must be a valid date value
SubjectSpecialization: Must be a valid subject area within the defined set
DepartmentName: Must be unique and non-null
Capacity: Must be a positive integer value
Bab 2.3
Bab 2.4
-- Sequence
CREATE SEQUENCE student_seq START WITH 1 INCREMENT BY 1;
-- Function
CREATE OR REPLACE FUNCTION generate_student_id RETURN INT IS
new_id INT;
BEGIN
SELECT student_seq.NEXTVAL INTO new_id FROM dual;
RETURN new_id;
END;
-- View
CREATE OR REPLACE VIEW student_view AS
SELECT s.StudentID, s.Name, s.DateOfBirth, s.Address, s.Grade, c.CourseName
FROM Student s
JOIN Enroll e ON s.StudentID = e.StudentID
JOIN Course c ON e.CourseID = c.CourseID;
-- Conditional Expression
UPDATE Student
SET Grade = CASE WHEN Grade IS NULL THEN 'NA' ELSE Grade END;
-- Subquery
SELECT *
FROM Teacher t
WHERE EXISTS (
SELECT 1
FROM Teach te
WHERE t.TeacherID = te.TeacherID
);