Hello. Tell me, please, how best to store the user's budget in mysql.

Is it better to store the budget in the same table, where is all the information about the user, or create a separate table budget_users and store there?

Are there any other ways to further protect the budget?

And I had an idea: if I keep a budget in the database and another budget in encrypted form (for example, I’ll substitute md5('Gg6&*:'.$budjet.'R%;i') values ​​on the right and left md5('Gg6&*:'.$budjet.'R%;i') ). And when the user tries to withdraw money, I check the budget with the encrypted budget. Do you think this method will be smooth?

  • Separate, foreign key on primary key of employee table + On delete cascade - Zowie
  • 2
    @AlexWinHope, why do you think in a separate? More keys to produce. It would not hurt to note that what you are saying will work with InnoDB only (from free ones) - Vitaly Kustov
  • @Vitaly Kustov - all adequate people and so use InnoDB (except for the rare case of need for fulltext index) Actually, I understand you need to read about normal forms - Zowie
  • one
    The shapes are great. But then the answer should probably be different. If @Artur Lodenev wants to work with the budget as an entity, then it is more likely that a more competent decision would be to put it in a separate table. If the budget has only an attribute of an entity, then why an extra table and keys? UPD: I personally came across hosting, where InnoDB simply does not exist. Awful, but fact - Vitaly Kustov
  • @Vitaly Kustov - if it's about finances, I suppose, InnoDB will be there. You wrote a more extensive answer yourself, I simply answered as briefly as possible, without consecrating the reasons - Zowie

2 answers 2

Together with user data. For security, do not give anyone access to the database, and everything is ok.

  • one
    Clear. Thank you very much for the quick feedback! - Arthur Lodenev

A separate table, moreover, with a date type field, magnification, reduction fields, so that you can get a "budget" for the date.