1

So I am creating a database and I have a few questions because I am not too sure if it's best to just add this to the users table or create a new table for it.

So my users table has the following fields:

id, shop_name, address, city, state, zip_code, email_address, username, password, last_login, forgot_password

So those are the basics of each shop. Now I need to add 3 fields:

timezone_id which pulls from another table.
primary_color which is going to be used as a hex color code
secondary_color which is also a hex color, for the main template colors.

From my understanding, if every single user will have the value filled out (so yes they will all have a time zone and have two colors, it cannot be blank) then it is appropriate to add to the users table.

Is that correct? Or would adding a table called colors be better and having an id, primary, secondary, user_id be better?

What are the pros and cons? Thank you!

Edit: So for example if I want to add a place for "slogans" but not every shop will have a slogan, would that be appropriate to create a new table for slogans and if a shop does decide to create their own then it would add it to the table?

I just want to see if I am understanding this correctly.

Drew
  • 6,736
  • 17
  • 64
  • 96

2 Answers2

4

As pro - you keep some of the entities separated - users and user_colors

Cons:

  • each time you have to access a user and its colors you have to do a join
  • also, each time a new user is inserted, you have to insert in 2 tables (this should be done in a transaction)
  • each time a user color is modified, you have to first find the user_id, then update in the colors table, whether otherwise you could simply update the user table with a simple where clause

I'd go for a single table

Tudor Constantin
  • 26,330
  • 7
  • 49
  • 72
1

I would just add this to your user table. There does not seem to be any reason for creating a new colours table. You would really only do this if each user would have an unlimited number of colours. Having it in one table means you can get all data from one table in one simple query rather than having to have a join or have seperate queries to get all data for a user.

With regards to the Slogans, again just add this to the user table. If they have a slogan, add this to the field, if they don't leave it blank. If a user was to have multiple slogans then perhaps then you would have this in a seperate table.

Perhaps familiarise yourself with database normalisation as this really helps when you are unsure of how to design your databases.

LeeTee
  • 6,401
  • 16
  • 79
  • 139
  • Oh ok, now I am starting to understand. So it is more for when multiple values are needed? Thanks so much for your help. – Drew Dec 19 '11 at 15:48