Are there reasons for not storing boolean values in SQL as bit data types?

后端 未结 11 1625
北恋
北恋 2020-12-29 02:44

Are there reasons for not storing boolean values in SQL as bit data types without NULL? I see them often stored as integers without constraints to limit values to 0 and 1,

11条回答
  •  攒了一身酷
    2020-12-29 03:00

    I'd always stick with the smallest data type I can to store this.

    • SQLServer: BIT
    • Oracle: NUMBER(1) (or BOOLEAN in PL/SQL)
    • MySQL: TINYINT (iirc BOOLEAN maps to this automatically)

    Edit: Oracle's BOOLEAN is PL/SQL only, not table definition. Updated answer to reflect this.

提交回复
热议问题