DB관련/SQL Server

Gender로 사용할 data type?

saltdoll 2015. 7. 31. 02:22
반응형

gender (성별)을 사용되는 데이터 타입은 어떤것이 좋을까요?


결론 부터 이야기 하자면,Char(1)을 추천하네요.

너무 단순한 질문일지 몰라도, DB의 데이터의 양을 줄이는 것에 대해서 신경을 쓰는 것은 유익한 노력입니다.




I'd call the column "gender".

Data Type   Bytes Taken          Number/Range of Values
------------------------------------------------
TinyINT     1                    255 (zero to 255)
INT         4            -       2,147,483,648 to 2,147,483,647
BIT         1 (2 if 9+ columns)  2 (0 and 1)
CHAR(1)     1                    26 if case insensitive, 52 otherwise

If there's a need to support more than two genders, the BIT data type can be ruled out for the sake it can't support them. While INT supports more than two options, it takes 4 bytes -- performance will be better with a smaller/more narrow data type.

CHAR(1) has the edge over TinyINT - both take the same number of bytes, but CHAR provides a more narrow number of values. Using CHAR(1) would make using "m", "f",etc natural keys, vs the use of numeric data which are referred to as surrogate/artificial keys. CHAR(1) is also supported on any database, should there be a need to port.

Conclusion

I would use Option 2: CHAR(1).

Addendum

An index on the gender column likely would not help because there's no value in an index on a low cardinality column. Meaning, there's not enough variety in the values for the index to provide any value.


출처: http://stackoverflow.com/questions/4175878/storing-sex-gender-in-database

반응형
도움이 되셨다면 하트모양의 "♡ 공감"을 눌러주시면 큰 격려가 됩니다.
(로그인하지 않으셔도 가능)