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

Yao Tung Ooi
Yao Tung Ooi
13,744 Points

In the case where you updated all emails to anon@email.com, what happens if the email field is a unique key?

In the case where you updated all emails to anon@email.com, what happens if the email field is a unique key?

1 Answer

Steven Parker
Steven Parker
231,236 Points

If a field is a unique key, then any attempt to write a value into a row that already exists in another row will fail and produce an error message.

Another result of making a field a unique key is that is cannot be optional. There can be at most one row where the field is null, in all other rows a unique value must be part of the record when it is inserted.