-2

I've created field named e2s with tinyint datatype. When I store the value of 500 it converts it into 127. Now I changed it to smallint. It stored value 500. Why? What is the difference between int, tinyint, smallint, mediumint, bigint to store values.

Christoph Diegelmann
  • 2,004
  • 15
  • 26
user2727841
  • 715
  • 6
  • 21

2 Answers2

1

Take a look at http://dev.mysql.com/doc/refman/5.0/en/integer-types.html. TINYINT only stores 1 byte of data, thus allowing the integer range of storage from -128 to 127.

SMALLINT in other hand uses 2 bytes of storage, having a much wider range from -32768 to 32767.

Be aware of what you are going to store in TINYINT or SMALLINT columns. For instance, it's a bad idea to set an auto_increment PK column to SMALLINT datatype as you could easily overwhelm it's capacity.

mathielo
  • 6,725
  • 7
  • 50
  • 63
0

Please see MySql reference on integer types:

http://dev.mysql.com/doc/refman/5.1/en/integer-types.html

It shows you the minimum and maximum values you can store.

Grzegorz
  • 3,207
  • 3
  • 20
  • 43