Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases Modifying Data with SQL Updating Data in a Database Update All Rows or Columns in a Table


When you update a value with SET are you changing that value permanently? If so, how could you recover the original value?

3 Answers

Yes John, unless the statement is placed in a transaction block (which would then require the committing of that transaction for it to be final), executing the UPDATE statement will permanently change the record or records. There is no simple way to recover the contents, hence the propensity in the DB community to create backups of both tables and databases.

Thomas Nilsen
Thomas Nilsen
14,957 Points

The closest you'll get is using something like this

Jon Phillips
Jon Phillips
1,217 Points

Would the command work if done on a primary key? And if so, would that make the table unuseable?

Yes Jon, I believe a primary key can be updated just like any other column. If it is an identity column the engine will complain and ask you to turn a specific flag off before doing so.

However, from a structural standpoint this is highly recommended against. You should never update primary key values and I cannot think of a situation where a workaround is not available.