I am looking for some help in the clarification of the UNIQUE key. For example, say I created a table and appended UNIQUE (email, activation, code) to the end of the CREATE statement. When inserting data, does the unique fields create a combined unique key or are they separate? In other words does an insert look for a row with all three unique fields to be the same or will it be unsuccessful if just one of the fields is a duplicate?

r937
—
2012-05-20T03:24:08Z —
#2

the combination of column values has to be unique

orange_floyd
—
2012-05-20T03:29:56Z —
#3

So to accomplish individual UNIQUE, it means that I have to do SELECT queries prior to make sure the values are not there?

r937
—
2012-05-20T03:54:19Z —
#4

you never have to do SELECTs to ensure uniqueness

what is it you want to do?

what was the purpose of declaring a 3-column composite UNIQUE key?

orange_floyd
—
2012-05-20T04:39:39Z —
#5

I was trying to understand how they work in concept. If I had a field for email and then a field for a salt key, I would want to make sure the email is UNIQUE and that the salt can only be in the database once as well. I guess if I created the salt with the email among other things, I shouldn't have to worry about that I suppose and can just have email as UNIQUE.

If the email is a UNIQUE field, does that mean with my coding language I shouldn't perform a select query, just try to insert the email and then check if the insert query succeeded to know if the email exists already or not?

r937
—
2012-05-20T09:59:27Z —
#6

orange_floyd said:

If the email is a UNIQUE field, does that mean with my coding language I shouldn't perform a select query, just try to insert the email and then check if the insert query succeeded to know if the email exists already or not?

yes

Mittineague
—
2014-09-23T07:33:48Z —
#7

This topic is now archived. It is frozen and cannot be changed in any way.