63

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

What is the difference between:

  • TinyINT(1)
  • TinyINT(2)
  • TinyINT(3)
  • TinyINT(4)
Community
  • 1
  • 1
Tarun Gupta
  • 1,232
  • 2
  • 13
  • 26

3 Answers3

66

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

muehlbau
  • 1,897
  • 13
  • 23
  • 1
    Am I correct in guessing that the maximum display width being 255 is unrelated to the maximum value of an unsigned TINYINT also being 255? That's just a coincidence? – Nathan Wailes Jun 05 '18 at 01:03
  • 2
    @NathanWailes yes. So realistically `TinyInt(3) unsigned` is sufficient to display the max _value_ of `255`. Whereas `TinyInt(4)` is need to display `-128` for instance. – colm.anseo Jul 16 '19 at 21:25
  • 1
    display of what .. where..?. if i am writing a client app,or web app, i only care about the value being retrieved, it's up to me how i format it / display it . yours confused. – joedotnot Jan 24 '20 at 22:42
7

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).

Vyktor
  • 20,559
  • 6
  • 64
  • 96
3

TinyINT = -128...+127

(n) is for display purposes.

Francois
  • 10,730
  • 7
  • 47
  • 80