Data type confusion: what is an int (11 )?, Confusionint

Source: Internet
Author: User

Data type confusion: what is an int (11 )?, Confusionint

Http://everythingmysql.ning.com/profiles/blogs/data-type-confusion-what-is-an

 

Over and over I see MERs that don't understand whatint(11)Really means. Their confusion is understandable. Unknown know what definingchar(10)Means (a fixed-sized character string that allows up to 10 characters). However, ints are different.

First of all, there are 5 types of integer. They are all fixed size.

Type # Of bytes
Tinyint 1
Smallint 2
Mediumint 3
Int 4
Bigint 8


As you can see from the chart,intIsAlways4 bytes. That can store signed numbers from-2 billion to + 2 billion (and unsigned numbers 0 to 4B). So, what does it mean if you declareint(5)? It does not restrict the number of digits to 5... It may be actually do nothing! The (5) part is a display width. it's only used if you use UNSIGNED and ZEROFILL with an integer type. then the display of those numbers will be zero-padded on the left to 5 digits if they contain less than 5 digits. example:


CREATE TABLE `foo` (
`bar` int(5) unsigned zerofill DEFAULT NULL
)

 SELECT * FROM foo;+---------+
| bar |
+---------+
| 00042 |
| 00101 |
| 9876543 |
+---------+

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.