database table design

When designing the table in the initial project, try to keep the table structure as clear as possible

method:

1. Try not to have redundant fields in the table;

     benefit:

     The table structure is clear;

     When repairing data, just modify one place, no need to modify other places;

2. Redundant fields in the table;

     a. Conditions:

    The data is immutable and the fields cannot be looked up from the association table;

    The data is unchanged, and the fields can be found in the association table, but the amount of data in the association table is huge (tens or millions), which affects performance;

     b. Benefits:

     Easy to query, no need to query through the association table

3. The vo field is built in the table or obtained by the get method, and is not serialized into the table.

      Fields whose data will change in real time;

      Fields that need to be calculated;

3. When designing the spring jpa framework table, you do not need to initialize the fields of the data, use the java reference type, otherwise the java primitive type (such as: boolean , int; Boolean, Integer)

4. Example:

     Under the enterprise, you can directly check the payment slip, inventory, invoice, and contract. At this time, the enterprise id should be associated with the Chinese medicine in the payment slip, inventory, invoice, and contract table, which is easy to find.

     The audit, processing process, etc. do not need to be searched by the enterprise, so you can not associate the enterprise id

Table design principles: https://baijiahao.baidu.com/s?id=1583861854199383399&wfr=spider&for=pc&isFailFlag=1

5. In the table design, the field design related to the amount

   When storing: try to use string storage to facilitate data migration, such as moving to solr, etc.

   When calculating: convert to BigDecimal, exact calculation

6. Fields of type long and int

   When storing: try to use Long, Integer and other types, unless there is a default value, use the original type. (Reason: It is convenient for the business to use NULL to determine whether the data exists)

6. Fields of boolean type

When storing: try to use types such as Boolean, unless there is a default value, use the original type. (Reason: When FastJson is serialized, getBoolean cannot be found, only isBoolean, which is inconvenient to operate. Solution: add a getBoolean method)




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326405624&siteId=291194637