Build a simple database in MySQL that includes several (2-4) tables.
Describe an ER diagram that shows the entities and relationships of this database. Pay attention to the limitations
Write a text file that contains SQL statements that create all the database tables.
Write a text file that contains SQL statements that fill all the tables of the database.
Create a database
Display its logical scheme in MySQL Workbench
The “Student Rating” database must store the following information:
Last name, First name, Patronymic of the student.
Home address of the student.
Student's phone number.
Date of birth.
Subject.
Month for which the rating is determined.
Current rating score.
The maximum rating score for the subject.
Last name, first name, patronymic of the teacher.
Many teachers can teach one subject, and many subjects can be taught by one teacher
The database should contain information about 10 students, 4 subjects, 2 teachers. provide that 5 students have a rating grade in at least 2 subjects.
Assistant
Sure! Below is a comprehensive guide to creating a simple MySQL database named "Student Rating". This guide includes:
Entity-Relationship (ER) Diagram Description
SQL Statements to Create Tables
SQL Statements to Populate Tables
Steps to Create the Database and Display Its Logical Schema in MySQL Workbench
1. Entity-Relationship (ER) Diagram Description
Entities:
Student
Attributes:
student_id (Primary Key)
last_name
first_name
patronymic
address
phone_number
date_of_birth
Teacher
Attributes:
teacher_id (Primary Key)
last_name
first_name
patronymic
Subject
Attributes:
subject_id (Primary Key)
subject_name
Rating
Attributes:
rating_id (Primary Key)
student_id (Foreign Key referencing Student)
subject_id (Foreign Key referencing Subject)
month
current_score
max_score
Teacher_Subject (Junction Table for Many-to-Many Relationship)
Attributes:
teacher_id (Foreign Key referencing Teacher)
subject_id (Foreign Key referencing Subject)
Primary Key:
Combination of teacher_id and subject_id
Relationships:
Student and Rating:
Type: One-to-Many
Description: A student can have multiple ratings (one for each subject per month).
Subject and Rating:
Type: One-to-Many
Description: A subject can have multiple ratings (one for each student per month).
Teacher and Subject:
Type: Many-to-Many
Description: A teacher can teach multiple subjects, and a subject can be taught by multiple teachers. This is implemented via the Teacher_Subject junction table.
MySQL Workbench installed for database management (optional but recommended).
Steps:
Open MySQL Workbench and connect to your MySQL server.
Execute the create_tables.sql Script:
Go to File > Open SQL Script and select create_tables.sql.
Review the script to ensure it's correct.
Click the Execute button (lightning bolt icon) to run the script.
This will create the StudentRating database along with all necessary tables and relationships.
Execute the insert_data.sql Script:
Similarly, open insert_data.sql in MySQL Workbench.
Review the insert statements.
Click the Execute button to populate the tables with sample data.
Verify the Data:
In MySQL Workbench, expand the StudentRating schema.
Right-click on each table (e.g., Student, Teacher) and select Select Rows - Limit 1000 to view the inserted data.
5. Displaying the Logical Schema in MySQL Workbench
MySQL Workbench provides a visual representation of your database schema through the EER (Enhanced Entity-Relationship) Diagram. Here's how to generate and view it:
Steps:
Open MySQL Workbench and ensure you're connected to the MySQL server where the StudentRating database resides.
Navigating to the Database:
In the Navigator pane on the left, under Schemas, find StudentRating.
Right-click on StudentRating and select Set as Default Schema.
Create EER Diagram:
Go to Database in the top menu.
Select Reverse Engineer....
Reverse Engineer Wizard will open:
Click Continue.
Ensure StudentRating is selected and click Continue.
Follow the prompts, ensuring all objects are selected.
Once completed, click Finish.
View and Modify the EER Diagram:
The EER diagram will appear in a new tab.
You can rearrange entities, adjust relationships, and customize the view as needed.
To save the diagram, go to File > Save Model or Export... to export as an image or PDF.
Note: The EER diagram will visually display all tables, their columns, primary keys, foreign keys, and the relationships between tables as defined in your SQL scripts.
Summary
You have successfully:
Designed an ER diagram for the StudentRating database.
Created SQL scripts to define the database schema and populate it with sample data.
Loaded the database into MySQL.
Generated a visual representation of the database schema using MySQL Workbench.
This setup provides a foundational structure for managing student ratings across various subjects and teachers. You can further expand this database with additional features such as user authentication, more detailed rating histories, or integration with other educational tools as needed.