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

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

Over and over I see customers that don‘t understand what 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

As you can see from the chart, an int is 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 |
+---------+
时间: 2024-12-28 04:15:59

Data type confusion: what is an int(11)?的相关文章

C++数据类型(data type)介绍

在编写程序时,数据类型(data type)定义了使用存储空间的(内存)的方式. 程序员通过定义数据类型(data type),告诉特定存储空间这里要存储的数据类型是什么,以及你即将操作他的方式.(注:存储空间有:堆存储,栈,静态存储等,后面再仔细去研究) 1.数据类型可以是内部的或者抽象的. 内建数据类型: 内建数据类型是编译器可以理解的数据类型,直接与编译器关联.C++在这里几乎完全继承了C 的数据类型.或者称为基本数据类型 抽象数据类型: 可以先理解为一个类(C++灵魂的精髓,数据类型:类

PHP 笔记一(systax/variables/echo/print/Data Type)

PHP stands for "Hypertext Preprocessor" ,it is a server scripting language. What Can PHP Do? PHP can generate dynamic page content PHP can create, open, read, write, delete, and close files on the server PHP can collect form data PHP can send an

Linux C double linked for any data type

/************************************************************************** * Linux C double linked for any data type * 声明: * 提供一种双链接口,可以保存保存任何类型的数据. * * 2015-12-25 晴 深圳 南山平山村 曾剑锋 **********************************************************************

int(1)和int(11)的区别

在cmd中进入数据库中 creata table t(x int(1) zerofill,y int(11) zerofill); insert into t(x,y) values(1,1); select x,y from t; 然后我们再创建一张表 我们比较一下可以发现int(1)和int(11)使用zerofill后两者才会有所区别,当没有加zerofill时候两者是没有任何区别的. 因此当结合可选扩展属性zerofill使用时, 默认补充的空格用零代替.例如,对于声明为INT(5) z

JAVA 1.2(原生数据类型 Primitive Data Type)

1. Java的数据类型分为2类 >> 原生数据类型(primitive data type) >> 引用数据类型(reference data type) 3. 常量和变量 常量: 所谓常量,就是值不会变化的量: 变量,就是值可以变化的量. 4. 如何定义和使用变量? int a; //变量的申明 a = 10; // 变量的初始化 int b = 20; // 变量的申明和初始化 注意事项: 如果没有初始化会出以下结果: 在Java中的== 和= 的区别: =  代表的是赋值操

int(11)最大长度是多少,MySQL中varchar最大长度是多少(转)

int(11)最大长度是多少,MySQL中varchar最大长度是多少? int(11)最大长度是多少? 在SQL语句中int代表你要创建字段的类型,int代表整型,11代表字段的长度. 这个11代表显示宽度,整数列的显示宽度与mysql需要用多少个字符来显示该列数值,与该整数需要的存储空间的大小都没有关系,比如,不管设定了显示宽度是多少个字符,bigint都要占用8个字节. int是整型,(11)是指显示字符的长度,但要加参数的,最大为255,比如它是记录行数的id,插入10笔资料,它就显示0

salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解

建立好的数据表在数据库中查看有很多方式,本人目前采用以下两种方式查看数据表. 1.采用schema Builder查看表结构以及多表之间的关联关系,可以登录后点击setup在左侧搜索框输入schema Builder 或者build-->schema Builder进入: 2.采用force.com Explorer通过自己写查询语句来查询数据. 此链接为force.com Explorer的下载链接:  http://force-com-explorer-beta.software.infor

nodes() Method (xml Data Type)

https://docs.microsoft.com/en-us/sql/t-sql/xml/nodes-method-xml-data-type The nodes() method is useful when you want to shred an xml data type instance into relational data. It allows you to identify nodes that will be mapped into a new row. Every xm

Linux C single linked for any data type

/************************************************************************** * Linux C single linked for any data type * 声明: * 提供一种单链接口,可以保存保存任何类型的数据,有时候这种需求在 * 很多场合还是会用到的. * * 2015-7-5 晴 深圳 南山平山村 曾剑锋 **************************************************