Home > Database > Mysql Tutorial > body text

what is mysql int

青灯夜游
Release: 2022-06-15 17:40:03
Original
8998 people have browsed it

In mysql, int is a standard integer type that can represent ordinary-sized integers. The int data type occupies 4 bytes and can be signed or unsigned. The storage range when signed is "-2147483648~2147483647", and the storage range when unsigned is "0~4294967295"; set the int type field It can have the AUTO_INCREMENT attribute to realize the automatic growth of the sequence value.

what is mysql int

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

mysql int type

In mysql, int is a standard integer type, which can represent ordinary-sized integers. Occupies 4 bytes. Fields of type int can be set to have the AUTO_INCREMENT attribute to achieve automatic growth of sequence values.

MySQL supports all standard SQL integer types INTEGER or INT and SMALLINT. In addition, MySQL provides standard SQL TINYINT MEDIUMINT and BIGINT as an extension of standard SQL.

MySQL INT data type can be signed or unsigned. The following table illustrates the characteristics of each integer type, including storage in bytes, minimum and maximum values.

Type Storage (bytes) Signed Unsigned
Minimum value Maximum value Minimum value Maximum value
TINYINT 1 -128(-24) 127(24) 0 255(28)
SMALLINT 2 -32768(-28) 32767(-28) 0 65535(-216)
MEDIUMINT 3 -8388608(-212) 8388607(-212) 0 16777215(-224)
INT 4 -2147483648(-216) 2147483647(-216) 0 4294967295(-232)
BIGINT 8 -9223372036854775808(-232) 9223372036854775807(-232) 0 18446744073709551615(-264)

MySQL INT and Display Width Properties

MySQL provides an extension that allows you to specify the display width and INT data type. The display width is contained in parentheses after the INT keyword, for example, INT(5) specifies that the INT display width is a five-digit a.

It is important to note that the display width attribute does not control the range of values ​​that the column can store. Applications typically use the display width attribute to format integer values. MySQL includes the display width attribute as metadata for returned result sets.

MySQL INT has the ZEROFILL attribute

In addition to display width, MySQL also provides the non-standard ZEROFILL attribute. In this case, MySQL replaces spaces with zeros. Consider the following example.

First, zerofill_tests creates a table named:

CREATE TABLE zerofill_tests(
    id INT AUTO_INCREMENT PRIMARY KEY,
    v1 INT(2) ZEROFILL,
    v2 INT(3) ZEROFILL,
    v3 INT(5) ZEROFILL
);
Copy after login

Second, insert a new row in the zerofill_tests table.

INSERT into zerofill_tests(v1,v2,v3)
VALUES(1,6,9);
Copy after login

Third, query data from the zerofill_tests table.

SELECT 
    v1, v2, v3
FROM
    zerofill_tests;
Copy after login

what is mysql int

The v1 column has a display width of ZEROFILL of 2. So it has a value of 1 and therefore, you can see 01 in the output. MySQL replaces the first space with 0.

The display width of column v2 is ZEROFILL of 3. Therefore, its value is 6 and other values ​​are filled with 00.

The v3 column has a display width of ZEROFILL of 5, and its value is 9, so MySQL pads at the beginning of the 0000 number in the output.

Note: If you use the ZEROFILL attribute on an integer column, MySQL will automatically add the UNSIGNED attribute to the column.

[Related recommendations: mysql video tutorial]

The above is the detailed content of what is mysql int. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template