MySQL Practice Exercises: Essential Techniques for Mastering the Framework

Here’s a short practice to help you get started with MySQL:

  1. Connect to the MySQL server using the MySQL command line tool.
  2. Create a new database named “practice_db” using the following command: “CREATE DATABASE practice_db;”
  3. Use the newly created database using the following command: “USE practice_db;”
  4. Create a new table named “students” with columns for “id”, “name”, “age”, and “email” using the following command: “CREATE TABLE students (id INT PRIMARY KEY, name VARCHAR(50), age INT, email VARCHAR(100));”
  5. Insert some data into the “students” table using the following commands:
sqlCopy codeINSERT INTO students (id, name, age, email) VALUES (1, 'John Doe', 22, 'johndoe@example.com');
INSERT INTO students (id, name, age, email) VALUES (2, 'Jane Doe', 20, 'janedoe@example.com');
INSERT INTO students (id, name, age, email) VALUES (3, 'Bob Smith', 25, 'bobsmith@example.com');
  1. Retrieve all data from the “students” table using the following command: “SELECT * FROM students;”
  2. Retrieve only the names and emails of students using the following command: “SELECT name, email FROM students;”
  3. Update the age of the student with id “2” to “21” using the following command: “UPDATE students SET age = 21 WHERE id = 2;”
  4. Delete the student with id “3” using the following command: “DELETE FROM students WHERE id = 3;”

These are the basic commands for working with a MySQL database. With these commands, you should be able to perform basic operations such as creating a database, tables, and inserting, retrieving, updating, and deleting data.

Tags: No tags

Add a Comment

Your email address will not be published. Required fields are marked *