Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql int fields does not truncate

as all you know, when you describe varchar or integer fields you should set the length of them...

something like int(5) or varchar(5)...

but when you try add 123456 to both fields.. while varchar field truncates the value, integer field does not truncate it...

so what's the aim of describing int length?

like image 819
Yasin Ergul Avatar asked Dec 13 '22 17:12

Yasin Ergul


1 Answers

int(5) does not do what you think it does: it specifies an integer field with a display width of 5 digits, i.e. numbers shorter than 5 digits will be padded with space characters.

In MySQL, int values are always 4 bytes wide and can go from -2,147,483,648 to 2,147,483,647.

See http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html.

like image 129
Frédéric Hamidi Avatar answered Jan 01 '23 21:01

Frédéric Hamidi