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

后端 未结 7 2067
独厮守ぢ
独厮守ぢ 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条回答
  •  清酒与你
    2021-02-07 05:06

    Generally speaking, enum is better for things that don't change much, and it uses slightly fewer resources, since there's no FK checks or anything like to execute on insert etc.

    Using a lookup table is more elegant and or traditional and it's much easier to add and remove options than an enum. It's also easier to mass change the values than an enum.

提交回复
热议问题