-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_sql_queries.sql
88 lines (65 loc) · 2.39 KB
/
database_sql_queries.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
-- School Table: This table stores general information about the school.
CREATE TABLE School (
school_id INT PRIMARY KEY AUTO_INCREMENT,
school_name VARCHAR(100) NOT NULL,
location VARCHAR(100) NOT NULL,
-- Add other relevant fields like address, contact details, etc.
);
-- Class Table: This table stores information about each class.
CREATE TABLE Class (
class_id INT PRIMARY KEY AUTO_INCREMENT,
class_name VARCHAR(10) NOT NULL,
-- Add other relevant fields like class teacher, etc.
);
-- Section Table: This table stores information about each section within a class.
CREATE TABLE Section (
sectionId INT PRIMARY KEY,
sectionName VARCHAR(10) NOT NULL,
classId INT NOT NULL,
FOREIGN KEY (classId) REFERENCES Class(classId),
);
CREATE TABLE Student (
studentId INT PRIMARY KEY,
rollNo INT NOT NULL,
name VARCHAR(100) NOT NULL,
classId INT NOT NULL,
sectionId INT NOT NULL,
FOREIGN KEY (classId) REFERENCES Class(classId),
FOREIGN KEY (sectionId) REFERENCES Section(sectionId)
);
-- Teacher Table: This table stores information about teachers.
CREATE TABLE Teacher (
teacherId INT PRIMARY KEY ,
name VARCHAR(100) NOT NULL,
);
-- Teacher_Section Table: This table associates teachers with the sections they teach.
CREATE TABLE TeacherSection (
teacherSectionId INT PRIMARY KEY ,
teacherId INT NOT NULL,
sectionId INT NOT NULL,
FOREIGN KEY (teacherId) REFERENCES Teacher(teacherId),
FOREIGN KEY (sectionId) REFERENCES Section(sectionId)
);
-- Attendance Table: This table now includes a field for subject_id to associate attendance records with subjects.
CREATE TABLE Attendance (
attendanceId INT PRIMARY KEY,
studentId INT NOT NULL,
subjectId INT NOT NULL,
date DATE NOT NULL,
status ENUM('Present', 'Absent') NOT NULL,
FOREIGN KEY (studentId) REFERENCES Student(studentId),
FOREIGN KEY (subjectId) REFERENCES Subject(subjectId)
);
-- Subject Table: This table stores information about subjects.
CREATE TABLE Subject (
subjectId INT PRIMARY KEY ,
subjectName VARCHAR(100) NOT NULL
);
-- Class_Subject Table: This table associates subjects with classes.
CREATE TABLE ClassSubject (
classSubjectId INT PRIMARY KEY ,
classId INT NOT NULL,
subjectId INT NOT NULL,
FOREIGN KEY (classId) REFERENCES Class(classId),
FOREIGN KEY (subjectId) REFERENCES Subject(subjectId)
);