MySQL Int형 데이터의 크기에 대해 정리합니다.

 

MySQL의 Int형 데이터에 대한 전반적인 내용은 MySQL공식홈페이지에서,

https://dev.mysql.com/doc/refman/8.0/en/integer-types.html

 

MySQL :: MySQL 8.0 Reference Manual :: 11.1.2 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT,

11.1.2 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT MySQL supports the SQL standard integer types INTEGER (or INT) and SMALLINT. As an extension to the standard, MySQL also supports the integer types TINYINT, MEDIUMINT,

dev.mysql.com

 

Unsigned Int형에 관한 내용은 하기 홈페이지를 참고하였습니다. 

https://www.cs.utah.edu/~germain/PPS/Topics/unsigned_integer.html

 

Programming - Unsigned Integers

Unsigned Integers Unsigned integers are used when we know that the value that we are storing will always be non-negative (zero or positive). Note: it is almost always the case that you could use a regular integer variable in place of an unsigned integer. T

www.cs.utah.edu

 

Type Storage ( Bytes) Minimum Value
Signed
Minimum Value
Unsigned
Maximum Value
Signed
Maximum Value
Unsigned
TINYINT 1 -128 0 127 255
SMALLINT 2 -32768 0 32767 65535
MEDIUMINT 3 -8388608 0 8388607 16777215
INT 4 -2147483648 0 2147483647 4294967295
BIGINT 8 -2^63 0 2(^63)-1 2(^64)-1

 

위 표와 링크를 통해 하기 2가지 내용에 대해 알 수 있습니다.

 

1. TINY는 최대(unsigned의 경우에 한정) 255까지 표현 할 수 있다.

-> 각 타입별로 데이터할당 크기를 정확히 파악 할 필요가 있겠습니다.

 

2. 부호의 유무(signed, unsigned)에 따라 최대 데이터 표현 크기가 다르다.

-> 음의정수를 표현필요 유무를 고려하여 데이터타입을 지정 할 필요가 있겠습니다.

+ Recent posts