The document outlines the SQL commands to create a database schema for a school management system, including tables for teachers, classes, students, and attendance. It establishes relationships between these tables through foreign keys and includes sample data for teachers, classes, and students. The schema supports features like class enrollment and attendance tracking for students.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
9 views2 pages
Attendance System - SQL
The document outlines the SQL commands to create a database schema for a school management system, including tables for teachers, classes, students, and attendance. It establishes relationships between these tables through foreign keys and includes sample data for teachers, classes, and students. The schema supports features like class enrollment and attendance tracking for students.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2
-- Create teachers table
CREATE TABLE teachers (
id INT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(255) UNIQUE NOT NULL, password VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
-- Create classes table
CREATE TABLE classes ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, teacher_id INT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (teacher_id) REFERENCES teachers(id) ON DELETE CASCADE, UNIQUE(name, teacher_id) );
-- Create students table
CREATE TABLE students ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, email VARCHAR(255) UNIQUE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
CREATE TABLE attendance ( id INT AUTO_INCREMENT PRIMARY KEY, student_id INT NOT NULL, class_id INT NOT NULL, check_in TIMESTAMP NULL, check_out TIMESTAMP NULL, date DATE NOT NULL DEFAULT (CURRENT_DATE), UNIQUE(student_id, class_id, date), FOREIGN KEY (student_id) REFERENCES students(id) ON DELETE CASCADE, FOREIGN KEY (class_id) REFERENCES classes(id) ON DELETE CASCADE );