Insert User Data into SQLite

Beginner

Introduction

In this challenge, you'll be working with SQLite to insert user data into a database table. The goal is to populate a users table with three specific records, each containing an id, name, and age.

You'll need to connect to the users.db database located in the ~/project directory and use the INSERT INTO command to add the provided user data. Ensure that the name column is not left empty, as it's defined as NOT NULL. Successful completion involves inserting Alice, Bob, and Charlie's information correctly, which can be verified by querying the table and confirming the expected output.


Skills Graph

Insert User Data into SQLite

This challenge tests your ability to insert data into an SQLite database table.

Tasks

  • Insert the following three records into the users table:
    • id: 1, name: 'Alice', age: 25
    • id: 2, name: 'Bob', age: 30
    • id: 3, name: 'Charlie', age: 22

Requirements

  1. Connect to the SQLite database named users.db located in the ~/project directory.
  2. Use the INSERT INTO command to add the three specified records to the users table.
  3. Ensure that the name column is not left empty (NOT NULL).

Examples

After successfully inserting the data, querying the users table with SELECT * FROM users; should produce the following output:

1|Alice|25
2|Bob|30
3|Charlie|22

Hints

  • Use the sqlite3 command to connect to the database.
  • The INSERT INTO command requires you to specify the table name and the values to insert.
  • Remember to include all three columns (id, name, age) in your INSERT INTO statements.

Summary

In this challenge, you are tasked with inserting user data into an SQLite database. The initial setup involves installing the SQLite server and creating a users table with id, name, and age columns within the users.db database located in the ~/project directory.

The core task requires using the INSERT INTO command to add three specific user records (Alice, Bob, and Charlie) with their respective id, name, and age values into the users table. Successful completion is verified by querying the database to confirm the presence of each user's record.