Websphere
Websphere

Reputation: 603

Should I create a table for only few rows?

Good day everyone, I didn't find any answer to my question on the net. I have some tables in my db that contain only few rows and will not have more. For example:

1- status_orders (payed, declined, shipped, delivered, returned, ...)

2- payment_means (card, cheque, bank transfer, paypal, ...)

knowing that i have a multilingual website, i have to create other tables that contain translations which means more JOINS...

Do you think I should keep doing it like this or simply use a PHP array and store its key in the database or maybe there is another better way to deal with this!!

Thanks a lot

Upvotes: 0

Views: 961

Answers (2)

Rick James
Rick James

Reputation: 142366

There are times when it makes sense to have a table with one row with one column. So, odd-sized tables are sometimes the "right thing to use".

PHP is a tempting alternative, but how would you "persist" the information? And if you can JOIN this tiny table to something else, that might be simpler than mixing metaphors (SQL and PHP).

Think of the databases as the "source of truth" for all the data. Think of your client (PHP) as the "business logic engine" that manipulates that data and "presents" it (via a webpage, for example).

Upvotes: 1

Elferone
Elferone

Reputation: 364

I believe it is a good thing to have those values stored in the database.

If another system wants to query data from your database, it will be possible for that system to know what these statuses are. That won't be the case if these statuses are encapsulated in your code.

However, for the translations, I see 3 options:

  • Have a table where you stored them (will cause more join as you just mentioned)
  • Have a field for each value of your table and store the translations into a JSON array format

    [{language: "fr", value: "Description du type"}, {language: "en", value: "Description type"}]

  • Store the translations of your types in your PHP code

Upvotes: 1

Related Questions