Varchar or int for "type" fields

3

I have a type column with 6 options to save to the bank, is it best to save string as varchar or int and treat this in the front ? For example, when 1 is in the database, display certain string on the screen, and so on.

I know that int would have more performance, but would like to know if you have too much headache or risk of inconsistency. I thought of saving as varchar myself so I did not have to deal with it.

    
asked by anonymous 17.10.2016 / 14:39

1 answer

3

You can not say without understanding what you really want, to know the whole context.

I'd say it's best to use a int or even an integer type of smaller size since there are only 6 options.

I do not think it is desirable to have the text space occupied in the table. But the problem is worse if you have to rename one of these types. But it might be useful to do this.

This is considered an enumeration and some databases have their own way of dealing with this. But it is often more advantageous to have a standard table with the descriptions. Of course standardization generates some extra cost. But if everything goes well it will be in the cache and the cost will be very small. But it can be an exaggeration to do that.

The problem with dealing with the application is that if you need to change a name, or add a new type, you will have to treat it properly, not everyone knows how to do it correctly. But it is far from being wrong. It may be the simplest solution.

Risks always exist in each of these solutions. If you do wrong either one may not work right. But none have obvious risks even though they are right.

Take a look:

17.10.2016 / 14:57