MySQL int range and max value analysis

Source: Internet
Author: User
Tags numeric value

This represents the width of the display
The display width of the whole series and how many characters does MySQL need to display the column value, it has nothing to do with the size of the storage space required by the integer, for example, regardless of how many characters the display width is set, the bigint occupies 8 bytes.


int is an integral type, (11) is the length of the display character, but to add parameters, the maximum is 255, for example, it is the ID of the row number of records, insert 10 data, it shows 00000000001 ~~~00000000010, when the number of digits more than 11, it also shows only 11 digits, If you don't add that to the argument that it's 11 digits ahead plus 0, it won't add 0 to the front.


When declaring an integer data column, we can assign it a display width of M (1~255), such as int (5), specify a display width of 5 characters, and if you don't specify a display width for it, MySQL assigns it a default value. The display width is used only for display, and cannot limit the range of values and space occupied, such as: Int (3) consumes 4 bytes of storage space, and the maximum allowable value is not 999, but the maximum allowable for an int integral type.

MySQL has five types of integer data columns-Tinyint,smallint,mediumint,int and bigint. The difference between them is that the range of values is different and the storage space varies.
Adding the unsigned property to the integer data column disables negative numbers, starting with the 0 value.

int range

Type Bytes Minimum Value Maximum Value
(signed/unsigned) (signed/unsigned)
TINYINT 1 -128 127
0 255
SMALLINT 2 -32768 32767
0 65535
MEDIUMINT 3 -8388608 8388607
0 16777215
INT 4 -2147483648 2147483647
0 4294967295
BIGINT 8 -9223372036854775808 9223372036854775807
0 18446744073709551615

The following is a description of the official website

  code is as follows copy code

Be careful When considering ENUM (' T ', ' F ') as "true binary".

Example:
CREATE TABLE ' bits ' (
' Val ' ENUM (' T ', ' F ') not NULL
);

Mysql> INSERT into ' bits ' (' Val ') VALUES (' W '), (' T '), (' F ');
Query OK, 3 rows affected, 1 Warning (0.00 sec)
Records:3 duplicates:0 warnings:1

mysql> show Warnin GS;


+---------+------+------------------------------------------+| Level | Code | Message |+---------+------+------------------------------------------+| Warning | 1265 | Data truncated for column ' Val ' at row 1 |+---------+------+------------------------------------------+1 row in Set (0.00 Sec

Mysql> SELECT COUNT (DISTINCT val) from Bits;

+---------------------+|                   COUNT (DISTINCT val) |+---------------------+| 3 |+---------------------+1 row in Set (0.00 sec)

So, shouldn ' t a binary type have only two distinct values?
(Note that it isn ' t NULL.)

Explanation from Manual (10.4.4. The enum Type):
-----
If You insert a invalid value to an ENUM (which is, a string not present in the list of PE rmitted values), the empty string is inserted instead as a special error value. This string can is distinguished from a ' normal ' empty string by the fact, this string has the numeric value 0. More about this later

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.