简体   繁体   中英

How to design a schema/structure for Database for Attendance Management System?

I am going to develop an attendance portal for my university. I have tried but was unsuccessful in designing an efficient DB for the same. It must be able to record attendance for all subjects, all classes etc. Any leads will be appreciated.

Class --< Lecuture --< Attendance >-- Student

A Class has many Lectures , each Lecture belongs to only a single Class .

Each Student attends many Lectures , and each Lecture is attended by many Students .

CREATE TABLE class (
    class_id INT,
    class_name VARCHAR(100),
    CONSTRAINT class_id_pk PRIMARY KEY (class_id)
);
CREATE TABLE lecture (
    lecture_id INT,
    class_id INT,
    lecture_dt DATE,
    CONSTRAINT lecture_id_pk PRIMARY KEY (lecture_id),
    CONSTRAINT lecture_class_id_fk FOREIGN KEY (class_id) REFERENCES class (class_id)
);
CREATE TABLE student (
    student_id INT,
    student_first_name VARCHAR(20),
    student_last_name VARCHAR(20),
    CONSTRAINT student_id_pk PRIMARY KEY (student_id)
);
CREATE TABLE attendance (
    lecture_id INT,
    student_id INT,
    attendance_present INT CHECK (attendance_present in (0,1)),
    CONSTRAINT attendance_pk PRIMARY KEY (lecture_id, student_id),
    CONSTRAINT att_lecture_id_fk FOREIGN KEY (lecture_id) REFERENCES lecture (lecture_id),
    CONSTRAINT att_student_id_fk FOREIGN KEY (student_id) REFERENCES student (student_id)
);

To create a M:N relationship between student and lecture, create an association table called attendance . Note that the Primary Key of attendance is both the lecture_id and student_id , and that both of these fields have foreign keys back to their respective tables.

If your database has a boolean data type, you could use that for attendance_present . A value of False/0 indicates that the student missed the lecture. A value of True/1 indicates that the student attended. You could also include a on_time if you wanted to store that.

In reality, this would also need a Teacher table which had a many to many with Class . There would probably also need to be a Course (or Subject) Table with a one to many with Class . There could also be a Semester Table with a one to many with Course . A Class could also have a list of Students, so a ClassList association table would be good.

Semester --< Course --< Class --< Lecture --< Attendance >-- Student
              Teacher ---^  L--< ClassList---------------------^

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM