Introduction
In this project, you will learn how to update a student's GPA (Grade Point Average) in a database using the UPDATE statement in SQL.
👀 Preview
MySQL [edusys]> SELECT * FROM student WHERE name = "Snow";
+-------+------+-----------+----------+
| ID | name | dept_name | tot_cred |
+-------+------+-----------+----------+
| 70557 | Snow | Physics | 61 |
+-------+------+-----------+----------+
1 row in set (0.000 sec)
🎯 Tasks
In this project, you will learn:
- How to start the MySQL server and log into the MySQL terminal
- How to import a database script into the MySQL database
- How to use the
UPDATEstatement to modify data in a table - How to verify the updated data in the database
🏆 Achievements
After completing this project, you will be able to:
- Understand the basic SQL
UPDATEstatement and how to use it to modify data in a database - Gain experience in working with MySQL, including starting the server, logging in, and executing SQL scripts
- Develop skills in database management and data manipulation
Start MySQL and Import the Database
In this step, you will learn how to start the MySQL server and import the edusys.sql database script.
Open a terminal on your system.
Run the following command to start the MySQL service:
sudo /etc/init.d/mysql startLog into the MySQL terminal:
mysql -urootImport the
edusys.sqlscript into the MySQL database:SOURCE ~/project/edusys.sql
Update the Student's GPA
In this step, you will learn how to use the UPDATE statement to modify the tot_cred of the student with the name snow in the student table.
Open a new file named
updateInformation.sqlin the~/projectdirectory.Add the following code to the
updateInformation.sqlfile:USE `edusys` UPDATE student SET tot_cred = 61 WHERE name = "Snow";This code will update the
tot_credcolumn of the student with the namesnowto61.Save the
updateInformation.sqlfile.
Run the Update Script
In this step, you will learn how to run the updateInformation.sql script in the MySQL terminal.
In the MySQL terminal, run the following command to execute the
updateInformation.sqlscript:SOURCE ~/project/updateInformation.sqlVerify the update by running the following query:
SELECT * FROM student WHERE name = "Snow";You should see the updated
tot_credvalue of61for the student with the namesnow.+-------+------+-----------+----------+ | ID | name | dept_name | tot_cred | +-------+------+-----------+----------+ | 70557 | Snow | Physics | 61 | +-------+------+-----------+----------+ 1 row in set (0.000 sec)
Congratulations! You have successfully updated the student's GPA in the database using the UPDATE statement.
Summary
Congratulations! You have completed this project. You can practice more labs in LabEx to improve your skills.



