Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

INT(1) and INT(2) in Mysql Range and Limit to StoreData?

Tags:

php

mysql

IN Mysql :

INT(1) = 2147483647 and Store 4 byte,

then what about INT(2) = ? and Store ? byte...

I used in INT(1) more than 2147483647 it does not work ! also I used in INT(2) with same value it does not work ?? Why ?

Solution ?

like image 292
Nimesh Vagadiya Avatar asked Feb 06 '13 11:02

Nimesh Vagadiya


People also ask

What does Int 2 mean in MySQL?

In MySQL, INTEGER (INT) is a numeric value without a decimal. It defines whole numbers that can be stored in a field or column. In addition, MySQL supports the display_width attribute (for example, INT(1)) and the ZEROFILL attribute, which automatically adds zeros to the value depending on the display width.

What is the acceptable range for small integer in MySQL?

SMALLINT − A small integer that can be signed or unsigned. If signed, the allowable range is from -32768 to 32767. If unsigned, the allowable range is from 0 to 65535.


1 Answers

The optional display width specifier is only applicable when using zerofill and has nothing to do with the internal size (in bytes) of the integer data type. It is always 4 bytes.

This optional display width may be used by applications to display integer values having a width less than the width specified for the column by left-padding them with spaces. (That is, this width is present in the metadata returned with result sets. Whether it is used or not is up to the application.)

Here's [a link] (http://dev.mysql.com/doc/refman/5.5/en/numeric-type-attributes.html)

Example For More

drop table if exists tablename;

create table tablename ( columnname int(4) unsigned zerofill not null default 0 );

insert into tablename (columnname) values (123),(456),(1234);

select * from tablename;

OutPut

0123

0456

1234

like image 104
Ronak Vyas Avatar answered Sep 25 '22 01:09

Ronak Vyas