What is the difference between tinyint, smallint, mediumint, bigint and int in MySQL?

前端 未结 6 2139
误落风尘
误落风尘 2020-11-29 14:43

What is the difference between tinyint, smallint, mediumint, bigint and int in MySQL?

In what cases should these be used?

6条回答
  •  半阙折子戏
    2020-11-29 14:48

    When it gets to real world usage of these datatypes, it is very important that you understand that using certain integer types could just be an overkill or under used. For example, using integer datatype for employeeCount in a table say employee could be an overkill since it supports a range of integer values from ~ negative 2 billion to positive 2 billion or zero to approximately 4 billion (unsigned). So, even if you consider one of the US biggest employer such as Walmart with roughly about 2.2 million employees using an integer datatype for the employeeCount column would be unnecessary. In such a case you use mediumint (that supports from 0 to 16 million (unsigned)) for example. Having said that if your range is expected to be unusually large you might consider bigint which as you can see from Daniel's notes supports a range larger than I care to decipher.

提交回复
热议问题