Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql tinyint(1) vs tinyint(2) vs tinyint(3) vs tinyint(4) [duplicate]

Tags:

mysql

Possible Duplicate:
MySql: Tinyint (2) vs tinyint(1) - Which difference?

What is the difference between:

  • TinyINT(1)
  • TinyINT(2)
  • TinyINT(3)
  • TinyINT(4)
like image 839
Tarun Gupta Avatar asked Oct 29 '12 11:10

Tarun Gupta


People also ask

What does Tinyint 4 mean?

So realistically TinyInt(3) unsigned is sufficient to display the max value of 255 . Whereas TinyInt(4) is need to display -128 for instance.

What does Tinyint 1 mean?

The TINYINT takes 1 byte that means it has range -128 to +127 while int takes 4 bytes; it has range -2147483648 to +2147483647.

What is Tinyint in MySQL?

TINYINT − A very small integer that can be signed or unsigned. If signed, the allowable range is from -128 to 127. If unsigned, the allowable range is from 0 to 255. You can specify a width of up to 4 digits.

When should I use Tinyint in MySQL?

TINYINT is a very small integer. The minimum and maximum SIGNED values are -128 and 127 respectively, while for UNSIGNED values TINYINT range is from 0 to 255. TINYINT uses 1 byte per row. It is the best option when you want to save space on your disk and enhance performance.


2 Answers

TinyINT(M) always has a range from -128..+127 signed or 0..255 unsigned. M is the display width.

M indicates the maximum display width for integer types. The maximum display width is 255. Display width is unrelated to the range of values a type can contain, as described in Section 11.2, “Numeric Types”. For floating-point and fixed-point types, M is the total number of digits that can be stored.

from http://dev.mysql.com/doc/refman/5.5/en/numeric-type-overview.html

like image 145
muehlbau Avatar answered Sep 28 '22 07:09

muehlbau


According to Mysql manual all decimal numeric types supports syntax:

Integer Types (Exact Value) 

When using DECIMAL it allows you to specify precision.

With *INT types it's has mainly display function which also specifies how many places should be added when using ZEROFILL.

The byte size remains unaffected (1B for TINYINT).

like image 42
Vyktor Avatar answered Sep 28 '22 07:09

Vyktor