본문 바로가기

SQL

[SQL] 테이블 생성 제약조건 정리

PK - Primary Key

NN - Not Null

BIN - Binary (stores data as binary strings. There is no character set so sorting and comparison is based on the numeric values of the bytes in the values.)

UN - Unsigned (non-negative numbers only. so if the range is -500 to 500, instead its 0 - 1000, the range is the same but it starts at 0)

UQ - Create/remove Unique Key

ZF - Zero-Filled (if the length is 5 like INT(5) then every field is filled with 0’s to the 5th digit. 12 = 00012, 400 = 00400, etc. )

AI - Auto Increment

G - Generated column. i.e. value generated by a formula based on the other columns

 

[정리]

제약조건 세부설명
PK (Primary Key) 기본키, 중복이나 빈 값이 들어올 수 없음
NN (Not Null) 빈 값이 들어올 수 없음
BIN (Binary) 데이터를 이진 문자열로 저장
UN (Unsigned) 마이너스 범위 삭제
UQ (Unique Key) 중복 값을 넣을 수 없음
ZF (Zero Filled) 컬럼 크기보다 작은 값을 넣었을 경우 0으로 채운 뒤 삽입
AI (Auto Increment) Insert 시마다 값 1씩 늘어남
G (Generated Column) 다른 열을 기반으로 한 수식으로 생성된 값