I was wondering what the difference between BigInt
, MediumInt
, and Int
are... it would seem obvious that they would allow for larger n
Let's give an example for int(10) one with zerofill keyword, one not, the table likes that:
create table tb_test_int_type(
int_10 int(10),
int_10_with_zf int(10) zerofill,
unit int unsigned
);
Let's insert some data:
insert into tb_test_int_type(int_10, int_10_with_zf, unit)
values (123456, 123456,3147483647), (123456, 4294967291,3147483647)
;
Then
select * from tb_test_int_type;
# int_10, int_10_with_zf, unit
'123456', '0000123456', '3147483647'
'123456', '4294967291', '3147483647'
We can see that
with keyword zerofill
, num less than 10 will fill 0, but without zerofill
it won't
Secondly with keyword zerofill
, int_10_with_zf becomes unsigned int type, if you insert a minus you will get error Out of range value for column.....
. But you can insert minus to int_10. Also if you insert 4294967291 to int_10 you will get error Out of range value for column.....
Conclusion:
int(X) without keyword zerofill
, is equal to int range -2147483648~2147483647
int(X) with keyword zerofill
, the field is equal to unsigned int range 0~4294967295, if num's length is less than X it will fill 0 to the left