Home  >  Article  >  Database  >  Data type: int

Data type: int

黄舟
黄舟Original
2017-02-07 11:35:501949browse

Integer type: int

INT[(M)] [UNSIGNED] [ZEROFILL]

M represents the maximum display width, the maximum is 255, I personally think it is meaningless when the defined value of M is 1 hour, it can also store up to 10 bits of data [Maybe this is just for front-end application display, right? ]

Size: 4 bytes

Storage range:

single(-2^(32-1),2^(32-1)-1]、unsingle(0,2^32-1)


##1.MySQL displays an optional display width indicator The form extends the SQL standard so that when a value is retrieved from the database, the value can be lengthened to a specified length. For example, specifying the type of a field as int(6) can ensure that values ​​containing less than 6 numbers can be automatically filled with spaces when retrieved from the database. It should be noted that using a width indicator does not Affects the size of the field and the range of values ​​it stores.


2. When the number exceeds the permitted range, it will be truncated and stored. Another special thing is that mysql will automatically change the value to 0 before inserting the illegal value into the table.

3. The ZEROFILL modification specifies that 0 (not spaces) can be used to fill the output value. Use this modifier to prevent the MySQL database from storing negative values.

mysql>create table t1(id int,id2int unsigned);
Query OK, 0 rows affected (0.13 sec)

Data type: int


Summary:

The default type of int when creating a table is signed, the default is 11, and the default for unsigned is 10.

int(M) In the integer data type, M represents the maximum display width.

In int(M), the value of M has nothing to do with how much storage space int(M) occupies.

It has nothing to do with the number of digits. int(3), int(4), and int(8) all occupy 4 btyes of storage space on the disk.

The maximum value of M is 255. Because int is an unsigned number, the maximum value is 4294967295 and the width is 10 bits, so it makes no sense to define int (255). So defining the width is meaningless.

The unsigned number defaults to 10, and the signed number defaults to 11, because there is a - sign, the sign bit.

The above is the content of data type: int. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn