Business Modeling: Enumeration field type selection

Source: Internet
Author: User
Tags numeric value
Select the appropriate enumeration value

When you build a database, you often encounter business requirements for fields such as status, gender, type, and so on.

These fields have a common feature, and their business implications are usually those of a few values. Such a field can be called an enumeration field.

Determine whether a field is an enumerated field and refer to the business meaning it expresses. If it is in the electric business, the commodity table has the commodity Type field, the General Electric dealer can add or delete the type dynamically, that is, the commodity type may have innumerable values, then it is not an enumeration field. Choose the right storage mode

For the gender field, we can use a numeric value such as 0,1,2 to represent it, or we can use ' M ', ' F ', such a type.
Again, a complex example of order status, it can have unpaid, paid, out of stock, delivered , etc. status, we can use 0,1,2,3 , etc. to express, also can use Unpay,pay_success,close such a string to represent.

In general, it can be represented by a pure numeric code or string encoding. The advantages and disadvantages of pure digital coding in the case of simple business meaning, such as the need for a field to indicate whether the business meaning is enabled , this business only is not enabled, has enabled these two business implications, this time using 0,1 such a pure figure is more appropriate and easy to understand. When the business meaning is more significant (n>2,n is not infinite Doha), such as the need for a field to represent the order status of the business meaning, this time if the use of 0,1,2,3 such a number to express, in the business is not easy to understand. string encoding advantages and disadvantages of the above pure digital coding of the shortcomings of the analysis, if the order status of the business meaning of the use of unpay,pay_success,close string in the way words in the business above is more intuitive. One disadvantage of using a string representation enumeration is that it is possible that the string is too long to be a small problem in team development. For example, the order status has been paid status, there may be someone write pay_success, someone wrote pay-success. In this case, to establish common class unified processing, do not allow their own spelling, to avoid the possibility of error. Of course, to control the spelling rules of enumerated strings, for example, you can use only uppercase + underscores to reduce the likelihood of spelling errors. Summary

In general, there is a principle, whether using a pure number or a string, to represent an enumerated field, to easily and clearly represent the business meaning of the field.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.