Data type confusion: what is an int(11)?
2011-07-19 08:43
585 查看
Over and over I see customers that don't understand what
First of all, there are 5 types of integer. They are all fixed size.
As you can see from the chart, an
SELECT * FROM foo;
+---------+
| bar |
+---------+
| 00042 |
| 00101 |
| 9876543 |
+---------+
int(11)really means. Their confusion is understandable. Many know what defining a
char(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 |
intis always 4 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 declare an
int(5)? It does not restrict the number of digits to 5... It may 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 |
+---------+
相关文章推荐
- Data type confusion: what is an int(11)?
- The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not refere
- IT IS an IMPORTANT String for Input TYPE=File Field --enctype="multipart/form-data"
- 'date' is an invalid value for the SoapElementAttribute.DataType property. The property may only be specified for primitive types.
- No enclosing instance of type A is accessible. Must qualify the allocation with an enclosin
- The method dismissDialog(int) from the type Activity is deprecated
- W/ResourceType( 4896): Bad XML block: header size 215 or total size 0 is larger than data size 0
- No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing insta
- Thinking in java-11 Everything is an object
- Caused by: java.sql.SQLException: Driver's Blob representation is of an unsupported type: weblogic.j
- What is the key of Data Assimilation?
- android.util.AndroidRuntimeException Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? com.uethinking.microvideo.manag
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type H is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- No enclosing instance of type E is accessible. Must qualify the allocation with an en
- Python错误代码分析:莫名的[TypeError: 'int' object is not iterable]
- There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key ''.
- <java>No enclosing instance of type GraphicFrame is accessible. Must qualify the allocation with an
- 什么是游戏开发的实体系统框架 What is an entity system framework for game development