Question

I'm creating a file hosting service, but right now I am creating the account email activation part of registering. So I had to come up with a database structure.

And right now it's:

users
  id
  first_name
  last_name
  email
  password
  since
  active
  hash_activate

But I can do it like a relational database too:

users
  id
  first_name
  last_name
  email
  password
  since

activation
  id
  user_id
  hash
  active

What would be the best way to go about it? And why?

Was it helpful?

Solution

If every person has only one activation hash active at at time, then it's feasible to store it in same table with users.

However, one advantage of separating it is that users only have an activation hash for a brief period of time, so to keep the user records smaller, you could store the hashes in a separate table. Keeping the user records small keeps it more performant. In this case, you wouldn't have active column. You'd just delete inactive hashes.

If you do store the activation columns in the user table, just be sure to select the columns by name. E.g. in most cases, you'll want do this:

SELECT id, first_name, last_name, email, password
FROM users

Instead of:

SELECT *
FROM users

You'd only want to select the activation columns when you needed them.

OTHER TIPS

The second would only be sensible if one user could have multiple activations. You don't say whether this is true or false, so I couldn't possibly advise you.

If activations are a temporary thing, or having a hash defines someone as active, then make them different. Otherwise, that really won't matter.

However, neither is necessarily more or less relational than the other, without much more information. If you put a unique constraint on the combination of values in each row, and set each column up with a NOT NULL constraint, your first one would be quite relational.

You use a relational design when correctness of data, over time, is as important, if not more important, than what the application does with that data, and/or when data structure correctness/consistency is critical to the correct operation of an application, but might not necessarily be guaranteed by the application's own operation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top