MySQL Describe output explanation
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 MyS开发者_StackOverflow社区QL 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
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.
精彩评论