Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
217,571 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.