Differences in the usage of tinyint, smallint, int, and bigint types in mysql

Source: Internet
Author: User
Tags exit in

The usage of tinyint, smallint, int, and bigint types in mysql is different:

In MySQL, the value range of Tinyint is-128 to 127. The unsigned range is 0 to 255 (see the official MySQL 5.1 reference manual.) Tinyint occupies 1 byte of storage space, that is, 8 bits ). So how does Tinyint value range come from? Let's first look at the unsigned situation. The unsigned minimum value means that all eight bits are 0, and the value is 0 in decimal format. Therefore, the minimum value of the unsigned Tinyint is 0. the maximum unsigned value means that all 8 bits are 255, which is in decimal format. this is easy to understand.

How does a signed Tinyint value range come from? In a computer, the highest bit is used as the symbol. 0 indicates positive, 1 indicates negative, and the rest indicates numerical values. The minimum value of a signed 8-bit is

11111111 =-127

Negative value

Maximum value:
 
01111111 = more than 127

Positive Value

Bigint

Integer Data from-2 ^ 63 (-9223372036854775808) to 2 ^ 63-1 (9223372036854775807) (All numbers ). The storage size is 8 bytes.

Int

Integer Data from-2 ^ 31 (-2,147,483,648) to 2 ^ 31-1 (2,147,483,647) (All numbers ). The storage size is 4 bytes. The SQL-92 synonym for the int Is integer.

Smallint

Integer Data from-2 ^ 15 (-32,768) to 2 ^ 15-1 (32,767. The storage size is 2 bytes.
 
Tinyint

Integer Data from 0 to 255. The storage size is 1 byte.

Note:

The bigint data type is supported where integer values are supported. However, bigint is used in some special cases. When the integer value exceeds the range supported by the int data type, bigint can be used. In SQL Server, the int data type is the main integer data type.

In the data type precedence table, bigint is located between smallmoney and int.

The function returns bigint only when the parameter expression is of the bigint data type. SQL Server does not automatically upgrade other integer data types (tinyint, smallint, and int) to bigint.

Articles you may be interested in
  • Use break, continue, goto, return, and exit in multiple loops in PHP
  • Differences and usage of select into from and insert into select
  • Differences among scrollHeight, scrollWidth, scrollLeft, and scrolltop in javascript
  • Differences between echo, print, print_r, var_export, and var_dump in php
  • Differences and usage of return, exit, break, and contiue in PHP
  • Differences between window. navigate and window. location. href
  • Detailed explanation of the difference between display: inline; and float: left;
  • Usage of several keywords such as $ this, static, final, const, and self in php

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.