Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Sometimes you need to use SQL to update values in all rows or columns of a table, whether to fix an error, update a status, or something else. This video will show you how to update data in SQL.
SQL Used
An update statement for all rows:
UPDATE <table> SET <column> = <value>;
The =
sign is different from an equality operator from a WHERE
condition. It's an assignment operator because you're assigning a new value to something.
Examples:
UPDATE users SET password = "thisisabadidea";
UPDATE products SET price = 2.99;
Update multiple columns in all rows:
UDPATE <table> SET <column 1> = <value 1>, <column 2> = <value 2>;
Examples:
UPDATE users SET first_name = "Anony", last_name = "Moose";
UPDATE products SET stock_count = 0, price = 0;
See all of the SQL used in Modifying Data With SQL in the Modifying Data With SQL Cheatsheet.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Yao Tung Ooi
13,744 PointsIn the case where you updated all emails to anon@email.com, what happens if the email field is a unique key?
Posted by Yao Tung OoiYao Tung Ooi
13,744 Points1 Answer
-
Kevin Haller
5,940 PointsUPDATE books SET title="test", author="test2"; Error: disk I/O error Refreshing the browser doesn't help.
Posted by Kevin HallerKevin Haller
5,940 Points1 Answer
-
John Fowler
7,913 Points3 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up