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)에 따라 최대 데이터 표현 크기가 다르다.
-> 음의정수를 표현필요 유무를 고려하여 데이터타입을 지정 할 필요가 있겠습니다.
'웹개발자공부 > MySQL' 카테고리의 다른 글
MySQL - 원격 서버 접속 시 터미널 명령어 (0) | 2023.01.03 |
---|---|
MySQL - AWS RDS 배포 시 .env파일 작성 예시 (0) | 2023.01.03 |
MySQL - 집계함수, JOIN, JSON_ARRAYAGG를 활용한 데이터 출력 (0) | 2022.12.11 |
MySQL - TypeORM을 사용하여 node.js서버 API 작성하기 (0) | 2022.10.19 |
MySQL - 이름에 공백(스페이스)이 들어간 데이터베이스 선택하기 (0) | 2022.10.18 |