Just I wonder why the range is given with the my sql data types. I define a table with a field name \"id\" and the data type is \"int(2)\". I inserted the value to the field
The optional display width specifier (for integer data types) is only applicable when using zerofill and has nothing to do with the internal size (in bytes) of the integer data type.
http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
drop table if exists foo;
create table foo
(
bar smallint(4) unsigned zerofill not null default 0
)engine=innodb;
insert into foo (bar) values (781),(727);
select * from foo;
+-----------+
| bar |
+-----------+
| 0781 |
| 0727 |
+-----------+
More importantly, what you should be thinking about is whether your integer data types should be signed or unsigned e.g.
create table users
(
user_id int not null auto_increment primary key, -- -2147483648 to 2147483647
...
)engine=innodb;
vs.
create table users
(
user_id int unsigned not null auto_increment primary key, -- 0 to 4294967295
...
)engine=innodb;
So, which is it to be - unsigned or signed ??
Hope this helps :)