MySQL Data type detailed

Source: Internet
Author: User
Tags mysql in time and date

MySQL data types include

1. Integer type, floating-point type, and fixed-point number type

2. Time and Date type

3. String type

4. Binary type

Integer type

Standard SQL supports integer,smallint these two types of integers, MySQL in addition to these two there are other, see the table below

type size Range (signed) range (unsigned) default width
TINYINT 1 bytes ( -128,127) (0,255) 4
SMALLINT 2 bytes ( -32 768,32 767) (0,65 535) 6
mediumint 3 bytes ( -8 388 608,8 388 607) (0,16 777 215) 8
int or integer 4 bytes ( -2 147 483 648,2 147 483 647) (0,4 294 967 295) one
BIGINT 8 bytes /td> ( -9 233 372 036 854 775 808,9 223 372 036 854 775 807) (0,18 446 744 073 709 551 615) 20 /td>
The number of bytes and the range of values for int and integer are the same, in fact, the int and the integer types are the same in MySQL

Why the unsigned range of tinyint is (0,255), because tinyint is 1 bytes and 1 bytes is 8 bits, then the maximum value of tinyint unsigned number is 28-1, that is, the maximum number of 255,tinyint signed is 27-1, or 127.

The same is true of other types.

MySQL support data type name is followed by the width, its basic form is data type (width value)

Q: Why is the default width of tinyint 4 instead of 3 and the maximum value is 255?

A: If it is a signed case, there will be a value of-128, and its width is 4.

MySQL Data type detailed

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.