Search code examples
mysqldatabaserelational-databasenormalization

MySQL - When to add new rows to user table and when to create new table?


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.


Solution

  • 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.