简体   繁体   中英

best practice to store Unlimited/Max value in DB

I have a few scenarios where I need to store an unlimited value (or maximum, whatever you like to call it), which represents no limitation in business.

A few options I considered:

  • Make the field Nullable, and Use DB NULL to represent such case. but the problem is I have to check it anywhere I need to do a comparison or display it.

  • Use actual Maximum value of the given type (for example, integer, i can use the largest Int32 value), but this need some tweaks at DB level - I have to write a constraint at the field (as I could use fixed length of decimal or Integer DB type) to limit the maximum value, and it could have no meaning to business either.

  • Use a predefined big value (that might make sense to the business) to represent it and store it at DB level, again, i have to write a constraint to the db field.

I have used all of them before for different scenarios, and all are not too bad, but you know, it's a pain to handle some specific cases.

My question is a bit broad: what do you guys suggest for this? what good/best practices are available?

Any help/suggestions are appreciated.

I would think that storing it as a separate column, IsXyzUnlimited , may be a good alternate practice.

Since it doesn't mean null, it may not be best to represent it as null. As you mentioned, there is also the problem of checking it before you invoke it.

Also, as you mentioned, the other 2 values could have business meaning. If you want the data to be self-revealing about the business, explicitly say "hey business, this thing is unlimited when this box is checked". No magic values.

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