Week5 Report
Week5 Report
<Title >
1. I will not plagiarize other students' reports or copy content from various
reports.
2. I will not obtain the main content of the report through internet websites or
other sources.
3. I will not manipulate the content of the report.
4. I will properly cite the sources of the documents I refer to when writing the
report.
5. I will not show my report to other students before submitting it.
I solemnly pledge to maintain ethical behavior while writing reports and uphold my
honor as a telecommunications engineering student.
When extended a database, tables such as class, club, employee should be used.
(Appropriate attributes can be added to each table)
Integrate the extended Inha database with Express (Check the extended Inha database with
DESC and SELECT commands)
2. Detailed Design
-- -----------------------------------------------------
-- Table `InhaUniDB`.`Class`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `InhaUniDB`.`Class` (
`idClass` INT NOT NULL,
`name` VARCHAR(45) NOT NULL,
`number_of_participants` INT NOT NULL,
`credits` INT NOT NULL,
`Room_idRoom` INT NOT NULL,
`Room_Building_Department_idDepartment` INT NOT NULL,
`Room_Building_IdBuilding` INT NOT NULL,
PRIMARY KEY (`idClass`, `Room_idRoom`, `Room_Building_Department_idDepartment`,
`Room_Building_IdBuilding`),
INDEX `fk_Class_Room1_idx` (`Room_idRoom` ASC, `Room_Building_Department_idDepartment`
ASC, `Room_Building_IdBuilding` ASC) VISIBLE,
CONSTRAINT `fk_Class_Room1`
FOREIGN KEY (`Room_idRoom` , `Room_Building_Department_idDepartment` ,
`Room_Building_IdBuilding`)
REFERENCES `InhaUniDB`.`Room` (`idRoom` , `Building_Department_idDepartment` ,
`Building_IdBuilding`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `InhaUniDB`.`club`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `InhaUniDB`.`club` (
`idclub` INT NOT NULL,
`clubName` VARCHAR(45) NOT NULL,
`max_student_enrollment` INT NOT NULL,
`during_time` INT NOT NULL,
`club_type` VARCHAR(45) NOT NULL,
`email` VARCHAR(45) NULL,
PRIMARY KEY (`idclub`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `InhaUniDB`.`employee`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `InhaUniDB`.`employee` (
`idemployee` INT NOT NULL,
`employeeName` VARCHAR(45) NOT NULL,
`position` VARCHAR(45) NULL,
`job_title` VARCHAR(45) NOT NULL,
`skills` VARCHAR(45) NOT NULL,
`Department_idDepartment` INT NOT NULL,
PRIMARY KEY (`idemployee`, `Department_idDepartment`),
INDEX `fk_employee_Department1_idx` (`Department_idDepartment` ASC) VISIBLE,
CONSTRAINT `fk_employee_Department1`
FOREIGN KEY (`Department_idDepartment`)
REFERENCES `InhaUniDB`.`Department` (`idDepartment`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `InhaUniDB`.`employee_has_Class`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `InhaUniDB`.`employee_has_Class` (
`employee_idemployee` INT NOT NULL,
`employee_Department_idDepartment` INT NOT NULL,
`Class_idClass` INT NOT NULL,
INDEX `fk_employee_has_Class_Class1_idx` (`Class_idClass` ASC) VISIBLE,
INDEX `fk_employee_has_Class_employee1_idx` (`employee_idemployee` ASC,
`employee_Department_idDepartment` ASC) VISIBLE,
CONSTRAINT `fk_employee_has_Class_employee1`
FOREIGN KEY (`employee_idemployee` , `employee_Department_idDepartment`)
REFERENCES `InhaUniDB`.`employee` (`idemployee` , `Department_idDepartment`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_employee_has_Class_Class1`
FOREIGN KEY (`Class_idClass`)
REFERENCES `InhaUniDB`.`Class` (`idClass`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `InhaUniDB`.`Student_has_Class`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `InhaUniDB`.`Student_has_Class` (
`Student_idStudent` INT NOT NULL,
`Class_idClass` INT NOT NULL,
PRIMARY KEY (`Student_idStudent`, `Class_idClass`),
INDEX `fk_Student_has_Class_Class1_idx` (`Class_idClass` ASC) VISIBLE,
INDEX `fk_Student_has_Class_Student1_idx` (`Student_idStudent` ASC) VISIBLE,
CONSTRAINT `fk_Student_has_Class_Student1`
FOREIGN KEY (`Student_idStudent`)
REFERENCES `InhaUniDB`.`Student` (`idStudent`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Student_has_Class_Class1`
FOREIGN KEY (`Class_idClass`)
REFERENCES `InhaUniDB`.`Class` (`idClass`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `InhaUniDB`.`Student_has_club`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `InhaUniDB`.`Student_has_club` (
`Student_idStudent` INT NOT NULL,
`Student_Department_idDepartment` INT NOT NULL,
`club_idclub` INT NOT NULL,
PRIMARY KEY (`Student_idStudent`, `Student_Department_idDepartment`, `club_idclub`),
INDEX `fk_Student_has_club_club1_idx` (`club_idclub` ASC) VISIBLE,
INDEX `fk_Student_has_club_Student1_idx` (`Student_idStudent` ASC,
`Student_Department_idDepartment` ASC) VISIBLE,
CONSTRAINT `fk_Student_has_club_Student1`
FOREIGN KEY (`Student_idStudent` , `Student_Department_idDepartment`)
REFERENCES `InhaUniDB`.`Student` (`idStudent` , `Department_idDepartment`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Student_has_club_club1`
FOREIGN KEY (`club_idclub`)
REFERENCES `InhaUniDB`.`club` (`idclub`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
EXPLANATION OF THESE CODES:
Class Table: Stores information about university classes, including their name, the number of
participants, credits, and the room where they are held. The table includes foreign keys to connect
classes with the corresponding room they are held in.
Club Table: Records details about university clubs, such as their name, maximum enrollment,
duration, type, and contact email.
Employee Table: Stores information about university employees, including their name, position,
job title, skills, and the department they belong to. A foreign key links employees to their
respective departments.
Employee_has_Class Table: Keeps track of class assignments for university staff. Establishes
foreign keys to associate staff members with the classes they teach.
Student_has_Class Table: Records the class enrollments of university students. Uses foreign keys
to link students with the classes they attend.
Student_has_club Table: Stores data about students' club memberships. Includes foreign keys to
connect students with the clubs they join.
These tables and their relationships are crucial for maintaining a well-organized and structured
database. Foreign keys play a vital role in ensuring data integrity and consistency by linking
records in one table to related records in other tables.
----------------------------------------------------------------------------------------------------------------
desc Class;
INSERT INTO Class( `idClass`, `name`, `number_of_participants`, `credits`,
`Room_idRoom`,`Room_Building_Department_idDepartment`,`Room_Building_IdBuilding` )
VALUES
(1, 'Math 101', 30, 3, 1, 1, 1),
(2, 'History 101', 25, 3, 2, 1, 2),
(3, 'English 101', 20, 3, 3, 2, 3),
(4, 'Physics 101', 35, 3, 4, 3, 4),
(5, 'Chemistry 101', 30, 3, 5, 3, 5);
select *from Class;
desc club;
INSERT INTO Club (`idClub`, `clubName`, `max_student_enrollment`, `during_time`,
`club_type`, `email`)
VALUES
(1, 'Chess Club', 50, 2, 'Hobby', '[email protected]'),
(2, 'Music Club', 40, 3, 'Arts', '[email protected]'),
(3, 'Science Club', 35, 2, 'Academic', '[email protected]'),
(4, 'Debate Club', 30, 2, 'Academic', '[email protected]'),
(5, 'Photography Club', 25, 2, 'Hobby', '[email protected]');
select *from club;
desc employee;
INSERT INTO Employee (`idEmployee`, `employeeName`, `position`, `job_title`, `skills`,
`Department_idDepartment`)
VALUES
(1, 'John Doe', 'Professor', 'Mathematics', 'Math, Calculus', 1),
(2, 'Jane Smith', 'Instructor', 'History', 'History, World Events', 1),
(3, 'Robert Johnson', 'Professor', 'English', 'English Literature, Writing', 2),
(4, 'Alice Brown', 'Instructor', 'Physics', 'Physics, Quantum Mechanics', 3),
(5, 'David Wilson', 'Professor', 'Chemistry', 'Chemistry, Organic Chemistry', 3);
select *from employee;
desc Student_has_Class;
INSERT INTO Student_has_Class(`Student_idStudent`,`Class_idClass`)
VALUES
(12235234,1,1),
(12235410,4,2),
(12235418,4,2),
(12235467,5,3),
(12235476,4,4);
select *from Student_has_Class;
desc Student_has_Club;
INSERT INTO
Student_has_Club(`Student_idStudent`,`Student_Department_idDepartment`,`Club_idClub`)
VALUES
(12235234,4,2),
(12235410,1,1),
(12235418,4,4),
(12235467,5,5),
(12235476,4,3);
select *from Student_has_Club;
desc employee_has_class;
INSERT
INTOEmployee_has_Class(`Employee_idEmployee`, `Employee_Department_idDepartment`,
`Class_idClass`)
VALUES
(1, 1, 1),
(2, 1, 2),
(3, 2, 1),
(4, 2, 3),
(5, 3, 2);
select *from employee_has_class;
INSERT INTO Table (...) VALUES ... statements insert data into tables. The values I provide
correspond to the columns in the table.
Displaying Table Data:
SELECT * FROM Table; statements retrieve and display all the records in a specific table.
1. Describing the "Class" Table---DESC Class; shows the structure of the "Class" table.
2. Inserting Data into the "Class" Table---The INSERT INTO Class statements add information about
university classes, including class ID, name, number of participants, credits, and room details.
3. Displaying the "Class" Table---SELECT * FROM Class; retrieves and displays all the class records.
This same pattern applies to the "club" and "employee" tables. So I did not write them.
===================================================================
2. Inserting Data into the "Student_has_Class" Table---Data is inserted to indicate which students
are enrolled in specific classes.
I repeated this pattern for the "Student_has_Club" and "Employee_has_Class" tables to describe,
insert data, and display their contents. These tables represent relationships between students and
clubs, and employees and classes, respectively.
In summary, the SQL code provided is for describing table structures, inserting data into tables,
and displaying data. It manages information related to university classes, student clubs,
employees, student-class enrollments, student-club memberships, and employee-class
associations.
----------------------------------------------------------------------------------------------------------
There is a many-to-many relationship between employee and class, which is non-identifying. that
is, this means that these tables are not dependent on each other, that is, if one is absent, the
other table can exist. Each has a unique ID number. Many professors can teach the same course or
one professor can teach many (different) courses, so the relationship between them is many-to-
many. Since there are other employees in the employee table, the relationship should be non-
identifying, because other employees have no relationship with the classes. Due to the many-to-
many relationship, a new table is created, its name is employee_has_class and it stores only
foreign keys.
CLASS-STUDENT RELATİONSHİP MANY-MANY(M-N):
The relationship between class and student is many-to-many and identfying because this class
table exists for students. And uses students' foreign key. Existence without them is absurd. So the
relationship is identfying. in addition, one class can be taken by many students or many classes can
be taken by the same student. so the connection is many-to-many. Due to the many-to-many
relationship, a new table is created, its name is student_has_class and it stores only foreign keys.
The relationship between student and club table is similar to the relationship between student
and class. Both tables are available for students and use its foreign key. İdentifying the relationship
between them is considered a many-to-many relationship. one student can participate in many
clubs and different students can participate in one club. Due to the many-to-many relationship, a
new table is created, its name is student_has_club and it stores only foreign keys.
There is also a relationship between room and class tables, this relationship is identifying and one
to many. Different classes can be held in one room. Every class must have its own room. İn the
meantime, the class table is optional, that's why there are rooms that are not intended for the
class.(may be it can be dormotory room and ets)
3. Execution Screenshots
When we apply select *from employee; it gives us all datas about this class. We can write rest of
classes like this.
If we want to add wrong class(that doesn’t exist) so it gives error like above.
So lets look at other classes:
4. Conclusion
Execution completed successfully. The results were printed using the terminal. And by entering
http://localhost:3000/ and typing select *from tablename, we get information about that table
from the database.
The additional tables are added to database and relations were established between tables.
Screenshots of successful results are shown above.