Add Student Personal Information

MySQLMySQLBeginner
Practice Now

Introduction

In this project, you will learn how to add student personal information to a database. You will start by learning how to set up the MySQL server and import the necessary database. Then, you will create a SQL script to insert new student records into the student table.

👀 Preview

MariaDB [edusys]> SELECT * FROM student WHERE ID = 93521 OR ID = 89212;
+-------+------+-----------+----------+
| ID    | name | dept_name | tot_cred |
+-------+------+-----------+----------+
| 89212 | Tang | Music     |       60 |
| 93521 | Rong | History   |       68 |
+-------+------+-----------+----------+
2 rows in set (0.000 sec)

🎯 Tasks

In this project, you will learn:

  • How to start the MySQL server
  • How to import a database using SQL scripts
  • How to use SQL INSERT statements to add new data to a table

🏆 Achievements

After completing this project, you will be able to:

  • Set up a MySQL server and import a database
  • Write SQL scripts to insert new data into a database table
  • Verify the inserted data using SQL queries

Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL mysql(("`MySQL`")) -.-> mysql/BasicKeywordsandStatementsGroup(["`Basic Keywords and Statements`"]) sql(("`SQL`")) -.-> sql/BasicSQLCommandsGroup(["`Basic SQL Commands`"]) sql(("`SQL`")) -.-> sql/DataManipulationandQueryingGroup(["`Data Manipulation and Querying`"]) sql(("`SQL`")) -.-> sql/DatabaseManagementandOptimizationGroup(["`Database Management and Optimization`"]) mysql/BasicKeywordsandStatementsGroup -.-> mysql/source("`External Code Execution`") sql/BasicSQLCommandsGroup -.-> sql/select("`SELECT statements`") sql/DataManipulationandQueryingGroup -.-> sql/where("`WHERE clause`") sql/DataManipulationandQueryingGroup -.-> sql/in("`IN clause`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/select("`Data Retrieval`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/insert("`Data Insertion`") sql/BasicSQLCommandsGroup -.-> sql/insert("`INSERT INTO statements`") sql/DatabaseManagementandOptimizationGroup -.-> sql/using_indexes("`Using Indexes`") subgraph Lab Skills mysql/source -.-> lab-301278{{"`Add Student Personal Information`"}} sql/select -.-> lab-301278{{"`Add Student Personal Information`"}} sql/where -.-> lab-301278{{"`Add Student Personal Information`"}} sql/in -.-> lab-301278{{"`Add Student Personal Information`"}} mysql/select -.-> lab-301278{{"`Add Student Personal Information`"}} mysql/insert -.-> lab-301278{{"`Add Student Personal Information`"}} sql/insert -.-> lab-301278{{"`Add Student Personal Information`"}} sql/using_indexes -.-> lab-301278{{"`Add Student Personal Information`"}} end

Start MySQL and Import the Database

In this step, you will learn how to start the MySQL server and import the database.

  1. Open a terminal on the server.

  2. Start the MySQL server:

    sudo /etc/init.d/mysql start
  3. Log into the MySQL terminal:

    mysql -uroot
  4. Import the edusys.sql script into the MySQL database:

    SOURCE ~/project/edusys.sql

This will create the necessary database and tables for the project.

Add Student Personal Information

In this step, you will learn how to add student personal information to the student table.

  1. Create a new file named insertInformation.sql in the ~/project directory.

  2. Open the file and add the following SQL statements:

    INSERT INTO edusys.student (ID, name, dept_name, tot_cred)
    VALUES (93521, 'Rong', 'History', 68),
           (89212, 'Tang', 'Music', 60);

    This will insert two new student records into the student table.

  3. Save the file.

  4. Run the SQL script in the MySQL terminal:

    SOURCE ~/project/insertInformation.sql

You can verify the new student records by running the following SQL query:

SELECT * FROM student WHERE ID = 93521 OR ID = 89212;

This should display the two new student records that you just added.

MariaDB [edusys]> SELECT * FROM student WHERE ID = 93521 OR ID = 89212;
+-------+------+-----------+----------+
| ID    | name | dept_name | tot_cred |
+-------+------+-----------+----------+
| 89212 | Tang | Music     |       60 |
| 93521 | Rong | History   |       68 |
+-------+------+-----------+----------+
2 rows in set (0.000 sec)

Summary

Congratulations! You have completed this project. You can practice more labs in LabEx to improve your skills.

Other MySQL Tutorials you may like