SQL: Advantages of an ENUM vs. a one-to-many relationship?

后端 未结 7 2241
独厮守ぢ
独厮守ぢ 2021-02-07 04:14

I very rarely see ENUM datatypes used in the wild; a developer almost always just uses a secondary table that looks like this:

CREATE TABLE officer_ranks (
id in         


        
7条回答
  •  -上瘾入骨i
    2021-02-07 05:12

    Advantages:

    • Type safety for stored procedures: will raise a type error if argument can not be coerced into the type. Like: select court_martial('3LT') would raise a type error automatically.

    • Custom coalition order: In your example, officers could be sorted without a ranking id.

提交回复
热议问题