Skip to content

xgg0213/aa10-sql-update-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Practice: UPDATE Data

Now, it's time to practice updating data in a database table using SQL.

Getting started

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

Create table

Run the following SQLite command to create the friends table, and insert the rows shown above.

.read seed-data.sql

Tip: 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.

Step 1: Update first name

Write and run a UPDATE statement to change Ryan Pond to Ryder Pond.

Step 2: Silent failure

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?

Congratulations!

You are now able to update data in a database using the SQL UPDATE statement.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published