0% 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.

Uploaded by

Naim Haque
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% 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.

Uploaded by

Naim Haque
Copyright
© © All Rights Reserved
Available Formats
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 Student Table


INSERT INTO Student (FirstName, LastName, DateOfBirth, Gender, Address, PhoneNumber, Email,
EnrollmentDate)
VALUES
('John', 'Doe', '2005-03-15', 'M', '123 Main St', '555-1234', '[email protected]', '2023-09-01'),
('Jane', 'Smith', '2006-07-22', 'F', '456 Elm St', '555-5678', '[email protected]', '2023-09-01');
-- Insert into Teacher Table
INSERT INTO Teacher (FirstName, LastName, DateOfBirth, Gender, Address, PhoneNumber, Email,
HireDate)
VALUES
('Alice', 'Johnson', '1980-05-10', 'F', '789 Oak St', '555-9876', '[email protected]', '2010-08-
15'),
('Bob', 'Williams', '1975-11-20', 'M', '321 Pine St', '555-4321', '[email protected]', '2015-03-
01');

-- Insert into Course Table


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');

-- Insert into Enrollment Table


INSERT INTO Enrollment (StudentID, CourseID, EnrollmentDate, Grade)
VALUES
(1, 1, '2023-09-01', 'A'),
(2, 2, '2023-09-01', 'B');

Two queries

SELECT s.StudentID, s.FirstName, s.LastName, c.CourseName


FROM Student s
JOIN Enrollment e ON s.StudentID = e.StudentID
JOIN Course c ON e.CourseID = c.CourseID;

SELECT c.CourseName, t.FirstName, t.LastName


FROM Course c
JOIN Teacher t ON c.TeacherID = t.TeacherID;

You might also like