What do numbers do when we create columns in databases?

7

Everyone who has worked with databases has already noticed that, during data modeling of a table, we can define a number in parentheses.

Examples:

INT(20)
TINYINT(4)
BIGINT(10)
VARCHAR(8)

If each data type has inherent in it the amount of bytes that can be stored, why are those numbers needed then? Also, does the number vary from paper to data type (for example, VARCHAR and INT )?

    
asked by anonymous 05.11.2015 / 13:52

2 answers

7

It may vary by implementation, but in general it determines the maximum number of characters that can be displayed in the column or the maximum that can be used in the column.

What it certainly does not determine is the amount of bytes it will occupy on the line. Texts can have encodings that a character has no direct relation to the amount of bytes being occupied. The storage of numbers will be done according to the implementation and each one may have a different consumption.

Then% w / o%, if this is possible, indicates that the number can be up to 20 digits.

A INT(20) indicates that the text can be up to 8 characters long. Some banks allow more storage to be stored. Some will occupy 8 bytes because this type does not have multibyte encoding. But it depends on the implementation. You have to look carefully at the documentation for each system.

    
05.11.2015 / 14:15
6

In the case of num, int, tinyint, bigint, the number in parentheses means the maximum number of digits. For the varchar and char fields, the number indicates the maximum number of characters.

    
05.11.2015 / 13:56