Encode measure in database field name

I have a question about fields in databases that can be displayed in different units, but stored only in one, for example, "height", for example.

Where should the "model unit" be indicated ?. Of course, in the documentation, etc. But we all know that no one reads the documentation and that self-documented things are preferable.

From a practical point of view, what do you think of coding in a database field (e.g. height_cm)?

I find it strange at first glance, but I find it practical to avoid mistakes when different people access the database directly and the “block of templates” never changes.

What do you think?

Sincerely.

+6
language-agnostic database coding-style
source share
4 answers

What is strange about height_cm? Looks nice.

Sometimes you see dimensions and units in two separate fields, which is much more painful.

As long as you know that the units will not change, I think that height_cm is a good way to handle this.

+8
source share

Most databases support column comments. For example, in Postgres you can set a comment like this:

COMMENT ON COLUMN my_table.my_column IS 'cm'; 

Storing the device name in this way means that your database is self-documenting. I also highly recommend using standard scientific units (i.e. Metric).

+2
source share

I agree that there is nothing wrong with adding a device to the field name.

The only thing I would like to say is to make the naming convention consistent in your database - for example, to avoid situations where both height_cm and mm_width are present in the same database!

0
source share

Be careful about measures that may change, like currencies. In many cases, this is not a practical renaming database field when it measures changes.

It's pretty silly to have a field called amount_mk , which was used to store the amount of money in stamps, but currently actually contains the amount of money in euros.

0
source share

All Articles