The document outlines the structure and SQL code for a school management system, including tables for Students, Teachers, Courses, and Enrollments. Each table is defined with its columns, data types, and constraints, along with example SQL commands for creating the tables and inserting data. Additionally, it includes two SQL queries for retrieving student enrollment information and course-teacher associations.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
5 views
ERD and MySQL Code
The document outlines the structure and SQL code for a school management system, including tables for Students, Teachers, Courses, and Enrollments. Each table is defined with its columns, data types, and constraints, along with example SQL commands for creating the tables and inserting data. Additionally, it includes two SQL queries for retrieving student enrollment information and course-teacher associations.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5
ERD and MySQL code of a school management systems
1. Student Table
Column Name Data Type Constraints
StudentID INT PRIMARY KEY, AUTO_INCREMENT FirstName VARCHAR(50) NOT NULL LastName VARCHAR(50) NOT NULL DateOfBirth DATE NOT NULL Gender CHAR(1) NOT NULL Address VARCHAR(100) PhoneNumber VARCHAR(15) Email VARCHAR(100) UNIQUE EnrollmentDate DATE NOT NULL
2. Teacher Table
Column Name Data Type Constraints
TeacherID INT PRIMARY KEY, AUTO_INCREMENT FirstName VARCHAR(50) NOT NULL LastName VARCHAR(50) NOT NULL DateOfBirth DATE NOT NULL Gender CHAR(1) NOT NULL Address VARCHAR(100) PhoneNumber VARCHAR(15) Email VARCHAR(100) UNIQUE HireDate DATE NOT NULL
3. Course Table
Column Name Data Type Constraints
CourseID INT PRIMARY KEY, AUTO_INCREMENT CourseName VARCHAR(100) NOT NULL CourseCode VARCHAR(20) NOT NULL, UNIQUE Credits INT NOT NULL Description TEXT 4. Enrollment Table
Column Name Data Type Constraints
EnrollmentID INT PRIMARY KEY, AUTO_INCREMENT StudentID INT FOREIGN KEY (StudentID) REFERENCES Student(StudentID) CourseID INT FOREIGN KEY (CourseID) REFERENCES Course(CourseID) EnrollmentDate DATE NOT NULL Grade CHAR(4)
-- Create Student Table
CREATE TABLE Student ( StudentID INT AUTO_INCREMENT PRIMARY KEY, FirstName VARCHAR(50) NOT NULL, LastName VARCHAR(50) NOT NULL, DateOfBirth DATE NOT NULL, Gender CHAR(1) NOT NULL, Address VARCHAR(100), PhoneNumber VARCHAR(15), Email VARCHAR(100) UNIQUE, EnrollmentDate DATE NOT NULL );
-- Create Teacher Table
CREATE TABLE Teacher ( TeacherID INT AUTO_INCREMENT PRIMARY KEY, FirstName VARCHAR(50) NOT NULL, LastName VARCHAR(50) NOT NULL, DateOfBirth DATE NOT NULL, Gender CHAR(1) NOT NULL, Address VARCHAR(100), PhoneNumber VARCHAR(15), Email VARCHAR(100) UNIQUE, HireDate DATE NOT NULL );
-- Create Course Table
CREATE TABLE Course ( CourseID INT AUTO_INCREMENT PRIMARY KEY, CourseName VARCHAR(100) NOT NULL, CourseCode VARCHAR(20) NOT NULL UNIQUE, Credits INT NOT NULL, Description TEXT );
-- Create Enrollment Table
CREATE TABLE Enrollment ( EnrollmentID INT AUTO_INCREMENT PRIMARY KEY, StudentID INT, CourseID INT, EnrollmentDate DATE NOT NULL, Grade CHAR(1), FOREIGN KEY (StudentID) REFERENCES Student(StudentID), FOREIGN KEY (CourseID) REFERENCES Course(CourseID) );
INSERT INTO Course (CourseName, CourseCode, Credits, Description) VALUES ('Mathematics', 'MATH101', 4, 'Introduction to Algebra and Calculus'), ('Science', 'SCI101', 3, 'Basic Principles of Physics and Chemistry');