Create a Sample Database
In this step, you will create a sample SQLite database and populate it with some data. This will give you a database to practice backing up and restoring.
First, open the SQLite shell. This is where you'll interact with the database.
sqlite3 mydatabase.db
This command starts the SQLite shell and creates a new database file named mydatabase.db. If the file already exists, it will open that file instead.
Now, create a table named users with columns for id, name, and email:
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT,
email TEXT
);
This SQL command creates a table named users. The id column is an integer and the primary key, which means it uniquely identifies each row in the table. The name and email columns are text fields.
Next, insert some sample data into the users table:
INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com');
INSERT INTO users (name, email) VALUES ('Bob', 'bob@example.com');
These commands add two rows to the users table. The first row has the name 'Alice' and the email 'alice@example.com'. The second row has the name 'Bob' and the email 'bob@example.com'.
To verify that the data has been inserted correctly, run the following command:
SELECT * FROM users;
You should see output similar to this:
1|Alice|alice@example.com
2|Bob|bob@example.com
This output shows the contents of the users table, confirming that the data has been inserted successfully.