felix9ia
V2EX  ›  数据库

数据库存储枚举字段应该用数值型还是字符串?

  •  
  •   felix9ia · Apr 15, 2025 · 2716 views
    This topic created in 584 days ago, the information mentioned may be changed or developed.

    应该用 code(smallint)?

    还是 name(varchar)?

    4 replies  •  2025-04-16 13:28:47 +08:00
    wu00
    wu00
    Apr 15, 2025
    1
    varchar 只有唯一的优势是查数据的时候不用再去看代码/DDL 注释
    wyntalgeer
    wyntalgeer
    Apr 15, 2025
    2
    用汉字
    abc0123xyz
    abc0123xyz
    Apr 16, 2025❤️2
    3
    @wyntalgeer 用 Emoji🥰
    mark2025
    mark2025
    Apr 16, 2025
    4
    难道不是用字符串枚举类型吗?
    字符串索引代价很大。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2329 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 02:48 · PVG 10:48 · LAX 18:48 · JFK 21:48
    ♥ Do have faith in what you're doing.