본문 바로가기
MySql

MySQL 내 SQL에서 "int"와 "int (2)"데이터 유형의 차이점

by 베이스 공부 2020. 10. 12.
반응형

왜 범위가 내 SQL 데이터 유형과 함께 제공되는지 궁금합니다. 필드 이름이 "id"이고 데이터 유형이 "int (2)"인 테이블을 정의합니다. 필드 "id"에 "123456"으로 값을 삽입했습니다. 이것은 승인되고 저장됩니다. 그래서 범위를 제공하는 용도는 무엇입니까?

미리 감사드립니다.

 

해결 방법

 

INT 및 속성이 표시되는 기타 숫자 유형의 경우 표시 너비 만 지정합니다.


MySQL은 다음에 대한 확장을 지원합니다. optionally specifying the display width of integer data types in parentheses following the base keyword for the type. For example, INT(4) specifies an INT with a display width of four digits. This optional display width may be used by applications to display integer values having a width less than the width specified for the column by left-padding them with spaces. (That is, this width is present in the metadata returned with result sets. Whether it is used or not 응용 프로그램에 달려 있습니다.)

디스플레이 너비는 제한하지 않습니다. the range of values that can be stored in the column. Nor does it prevent values wider than the column display width from being displayed correctly. For example, a column specified as SMALLINT(3) has the usual SMALLINT range of -32768 to 32767, and values outside the range permitted by three digits are displayed in full using 세 자리 이상.

 

참조 페이지 https://stackoverflow.com/questions/5562322

 

 

반응형

댓글