简体   繁体   中英

What's the best way to structure and store part of data in MySQL?

I have some doubts about how to propose the structure of a database, the dilema is if I have to store serialized data or it's better to make a table with relational fields.

An example of that is to supose that application:

  • Customers have fees to pay
  • These fees are generated based on the date of the first payment and the payment deadline
  • Imagine an online course of 600 euros and that you define as the date of the first payment 2022-01-01 and payment deadline 2022-03-01, there we would have 3 installments of 200 euros

I am currently proposing a structure in which we have:

  • A table "clients"
  • A table "courses"
  • A table "course_has_inscriptions"

Well, inside the table "course_has_inscriptions", we have the fields:

  • id
  • course_id
  • client_id
  • issue_date
  • deadline_date
  • next_payment
  • quotes [I WANT TO SAVE AN ARRAY OF SERIALIZED QUOTAS HERE]

The array looks like this:

$quotas = [];
$quotas ['2022-01'] ['value'] = 200
$quotas ['2022-02'] ['value'] = 200
$quotas ['2022-03'] ['value'] = 200

Are there any advantages if instead of doing so I do it inside another relational table of the type "quotes" where I store:

  • id
  • inscription_id
  • quote
  • value

Thank you

Always choose the easier option, which is another table. This is easier because the data is easier to access. If you serialize the data you would have to retrieve it and unserialize before you can use it, if you use another table you can simply retrieve and use it. You can actually use the power of MySQL queries.

Think about it. For instance, later you will make a table containing the payments and you want to check whether people paid what they needed to pay. If you serialize the data you cannot do that with MySQL, you are forced to do it in PHP, which is not what you want.

People, who have encountered this problem many times, have summarized their experience in a couple of rules. They call this data normalization .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM