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

前端 未结 6 2136
误落风尘
误落风尘 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 15:09

    The size of storage required and how big the numbers can be.

    On SQL Server:

    • tinyint 1 byte, 0 to 255
    • smallint 2 bytes, -215 (-32,768) to 215-1 (32,767)
    • int 4 bytes, -231 (-2,147,483,648) to 231-1 (2,147,483,647)
    • bigint 8 bytes, -263 (-9,223,372,036,854,775,808) to 263-1 (9,223,372,036,854,775,807)

    You can store the number 1 in all 4, but a bigint will use 8 bytes, while a tinyint will use 1 byte.

提交回复
热议问题