Now, it's time to practice updating data in a database table using SQL.
Download the starter. cd into the folder named sql-practice.
Run SQLite on a database called practice.db.
In this practice, you will use this example table to make your queries:
Table friends:
id |
first_name |
last_name |
|---|---|---|
| 1 | Ryan | Pond |
| 2 | Sky | Tyler |
| 3 | Morgan | Jones |
| 4 | Shannon | Noble |
| 5 | River | Song |
Run the following SQLite command to create the friends table, and insert the
rows shown above.
.read seed-data.sqlTip: You can rerun the command above any time you want to get back to the original seed data. This is helpful when working on statements that modify the database, in case you have any errors when you run one.
For the following steps, you should execute the SQL command in the SQLite3 CLI,
but you can create and use a .sql file to formulate the command.
Write and run a UPDATE statement to change Ryan Pond to Ryder Pond.
Copy/paste the following SQL statement into your SQLite CLI, and run it.
UPDATE friends
SET last_name = 'Blue'
WHERE first_name = 'Tyler'
AND last_name = 'Sky';How did this SQL statement change the data? Hint: Use SELECT statements.
If you feel like nothing happened, you would be correct. Now, can you fix the statement so it
will rename Sky Tyler to Sky Blue?
You are now able to update data in a database using the SQL UPDATE statement.