Draw a line between what DB should have as a master and what source code should define

Asked 2 months ago, Updated 2 months ago, 5 views

I'm worried about drawing a line between what DB should have as a master and what source code should define as a Const list.
Personally, if the user does not edit from the master management screen, I think it should be defined on the source code, but I don't get approval from people around me.

An extreme example is whether the on-screen display names "male" and "female" should be maintained in DB or associative array {0:"male", 1:"female"} in source code when retaining the gender column of the HR table with code value of 0.

Could you give me your opinion?

Supplemental

The reason why I think I should have it in source code is that if I have it in DB, I often hesitate whether or not to add records to the master without testing during future operations.

In this case, you need to know all the source code to determine if you just need to add a record to the master or if you need to modify the screen layout with the radio button.

Therefore, the criteria for determining exactly are not whether the user edits from the master management screen above, but whether the operation of adding, deleting, or changing records is guaranteed.

On the other hand, the reason why I heard so far that I should have a DB was persuasive is

  • You can tell if "1" is a man or a woman just by looking at the DB
  • Source code gets shorter
  • It's common practice to have it in DB, so it's less confusing to follow it

and so on.

database database-design

2022-09-30 11:21

2 Answers

Personally, if the user does not edit from the master management screen, I think it should be defined on the source code, but I don't get approval from people around me.

  • Why do you think the question should be "defined by source code"?
  • Why are people around you opposed to "defining with source code"?

Could you give me your opinion?

I can't decide which method to choose.Both have advantages and disadvantages.
Depending on the requirements, characteristics, and policy of the system, which one is more advantageous will change.

A)Managed by DB Master
Benefits

  • You may not need to build the source code when there is a change.

disadvantages

  • Slightly complicated SQL, affecting throughput and response.
  • It is expected that the display will look different depending on the situation, and it will be difficult to deal with.

B)Defined by source code

Benefits

  • Advantages in throughput and response over A) methods
  • It is expected that the display will look different depending on the situation, and in that case, it is easier to respond than A).

disadvantages

  • When there is a change, the source code needs to be built.
  • Coded all over source code makes it difficult to fix.
     表示You can reduce the disadvantages by localizing the impact, such as preparing a function to get the display name.


2022-09-30 11:21

I have a gender column of 0,1 in the HR table, so
I think it's better to have a gender table.
0—Men
1: Woman

Reason:
1. (If the developer knows how to combine the table with the gender table), the mistake of displaying male and female in reverse will be reduced.
2. If you have to add gender such as "other" or "unknown", it is easy to identify the changes.
3. If you later need a list box to select men and women, you can easily change it.
and so on

Gender codes (0 and 1) should not be written in the program as much as possible. It will be flexible (easy to maintain and resistant to changes).


2022-09-30 11:21

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.