0% found this document useful (0 votes)
14 views4 pages

For Dummy Database If Not Exists School - 012937

The document outlines the SQL commands to create a school management database with various tables for users, students, teachers, classes, subjects, grades, attendance, news, and financial systems. It includes relationships between tables through foreign keys and initial data for grading symbols. The structure supports functionalities such as grading, reporting, attendance tracking, and parent portal access.

Uploaded by

Sicelo Dlamini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

For Dummy Database If Not Exists School - 012937

The document outlines the SQL commands to create a school management database with various tables for users, students, teachers, classes, subjects, grades, attendance, news, and financial systems. It includes relationships between tables through foreign keys and initial data for grading symbols. The structure supports functionalities such as grading, reporting, attendance tracking, and parent portal access.

Uploaded by

Sicelo Dlamini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CREATE DATABASE IF NOT EXISTS school_management;

USE school_management;

CREATE TABLE users (


id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(50) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
role ENUM('admin','teacher','student','parent') NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE students (


id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT UNIQUE NOT NULL,
full_name VARCHAR(100) NOT NULL,
date_of_birth DATE NOT NULL,
parent_email VARCHAR(100) NOT NULL,
photo VARCHAR(255),
student_pin VARCHAR(20) UNIQUE,
class_position INT,
FOREIGN KEY (user_id) REFERENCES users(id)
);

CREATE TABLE teachers (


id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT UNIQUE NOT NULL,
full_name VARCHAR(100) NOT NULL,
qualification VARCHAR(100),
photo VARCHAR(255),
FOREIGN KEY (user_id) REFERENCES users(id)
);

CREATE TABLE classes (


id INT PRIMARY KEY AUTO_INCREMENT,
class_name VARCHAR(50) NOT NULL,
teacher_id INT NOT NULL,
academic_year YEAR,
FOREIGN KEY (teacher_id) REFERENCES teachers(id)
);

CREATE TABLE subjects (


id INT PRIMARY KEY AUTO_INCREMENT,
subject_name VARCHAR(50) NOT NULL,
class_id INT NOT NULL,
teacher_id INT NOT NULL,
schedule VARCHAR(50),
ca_weight FLOAT DEFAULT 0.5,
exam_weight FLOAT DEFAULT 0.5,
FOREIGN KEY (class_id) REFERENCES classes(id),
FOREIGN KEY (teacher_id) REFERENCES teachers(id)
);

CREATE TABLE grades (


id INT PRIMARY KEY AUTO_INCREMENT,
student_id INT NOT NULL,
subject_id INT NOT NULL,
term INT NOT NULL,
academic_year YEAR NOT NULL,
ca_score DECIMAL(5,2),
exam_score DECIMAL(5,2),
grade VARCHAR(2),
FOREIGN KEY (student_id) REFERENCES students(id),
FOREIGN KEY (subject_id) REFERENCES subjects(id)
);

CREATE TABLE attendance (


id INT PRIMARY KEY AUTO_INCREMENT,
student_id INT NOT NULL,
class_id INT NOT NULL,
date DATE NOT NULL,
status ENUM('Present','Absent') NOT NULL,
FOREIGN KEY (student_id) REFERENCES students(id),
FOREIGN KEY (class_id) REFERENCES classes(id)
);

CREATE TABLE news (


id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
author_id INT NOT NULL,
post_date DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (author_id) REFERENCES users(id)
);

-- Grading System
CREATE TABLE grade_symbols (
symbol VARCHAR(2) PRIMARY KEY,
description VARCHAR(20) NOT NULL,
min_percentage DECIMAL(5,2) NOT NULL,
max_percentage DECIMAL(5,2) NOT NULL
);

-- Reporting System
CREATE TABLE reports (
id INT PRIMARY KEY AUTO_INCREMENT,
student_id INT NOT NULL,
term INT NOT NULL,
academic_year YEAR NOT NULL,
term_start DATE NOT NULL,
term_end DATE NOT NULL,
overall_average DECIMAL(5,2),
class_position INT,
teacher_comment TEXT,
head_comment TEXT,
recommendation TEXT,
generated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (student_id) REFERENCES students(id)
);

CREATE TABLE subject_comments (


id INT PRIMARY KEY AUTO_INCREMENT,
report_id INT NOT NULL,
subject_id INT NOT NULL,
comment TEXT NOT NULL,
symbol VARCHAR(2) NOT NULL,
FOREIGN KEY (report_id) REFERENCES reports(id),
FOREIGN KEY (subject_id) REFERENCES subjects(id)
);

-- Financial System
CREATE TABLE student_fees (
id INT PRIMARY KEY AUTO_INCREMENT,
student_id INT NOT NULL,
total_fees DECIMAL(10,2) NOT NULL,
paid_amount DECIMAL(10,2) DEFAULT 0.00,
due_date DATE NOT NULL,
FOREIGN KEY (student_id) REFERENCES students(id)
);

-- Parent Portal System


CREATE TABLE parent_tokens (
id INT PRIMARY KEY AUTO_INCREMENT,
student_id INT NOT NULL,
token VARCHAR(64) UNIQUE NOT NULL,
expiry DATETIME NOT NULL,
FOREIGN KEY (student_id) REFERENCES students(id)
);

-- Initial Data
INSERT INTO grade_symbols (symbol, description, min_percentage, max_percentage)
VALUES
('E', 'Excellent', 90.00, 100.00),
('VG', 'Very Good', 80.00, 89.99),
('G', 'Good', 70.00, 79.99),
('A', 'Average', 50.00, 69.99),
('U', 'Unsufficient', 30.00, 49.99),
('VU', 'Very Unsufficient', 0.00, 29.99);

You might also like