1

This MySQL table is generated by ActiveRecord.

+--------------------+-------------+------+-----+---------+----------------+
| Field              | Type        | Null | Key | Default | Extra          |
+--------------------+-------------+------+-----+---------+----------------+
| id                 | int(11)     | NO   | PRI | NULL    | auto_increment |
| RecordType         | tinyint(4)  | YES  |     | NULL    |                |
| Location           | varchar(8)  | YES  |     | NULL    |                |

Please explain to me what is meant by tinyint(4) in the second column. According to MySQL documentation the size of tinyint is one bytes. But does this mean it takes actually 4 bytes to store this data. The code for generating the second column is like this.

t.column :RecordType, :integer, :limit => 1
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Indika K
  • 1,332
  • 17
  • 27
  • Related, if it's of interest, I wrote a *Describe All Tables* in [this Answer](http://stackoverflow.com/a/38679580). – Drew Jul 31 '16 at 00:53

1 Answers1

1

It means it uses 1 byte for that data type, not 4 so therefore the range of possible numbers is smaller (-128 to 127 or 0 - 255 for unsigned or 2^8 if you will which is 1 byte).

TINYINT(4) is the display length, so it means it'll use four digits to represent the number.

Michael J.V.
  • 5,499
  • 1
  • 20
  • 16