enums in SQL Server database

前端 未结 3 1250
抹茶落季
抹茶落季 2021-02-13 06:46

Is there a better or easier way to store the enums (Enumerations available in programming languages like C#) in SQL Server database other than simply creating a lookup table (wi

3条回答
  •  时光说笑
    2021-02-13 07:14

    As changing the enum inside your code will also require to release a new version of your application, I'd go for no lookup table at all, but only add a check constraint to the column in question.

    If you however need to store localized names of the enum in the database, then I'd go for one lookup table for each enum.

    The "one true lookup table" isn't going to give you any advantages.

    Edit: if you need to dynamically retrieve the enum values (e.g. for a dropdown) or need to find out which values are allowed, then using lookup tables is probably better for you.

提交回复
热议问题