enums in SQL Server database

前端 未结 3 782
北海茫月
北海茫月 2021-02-13 06:44

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:17

    Using the same table for several look-ups can come back to haunt you. One example is creating an Indexed View. This can help with performance if you have several fields where you want to display the lookup value, but SQL Server (at least 2005) won't allow you to reference the same table more than once (If this has been fixed, I would really like to know how to go about it because I could really use it in a current application with a single lookup table.).

    One of your lookups may require an additional field, and by using one table, you'll have a lot of unecessary nulls. Indexing can be more flexible with separate tables. What if the new field needs to be required for one particular type of lookup? SQL Server will do well with a constraint, but when thrown in the same table a little more complexity is going to be needed.

    You may not have any of these issues right now. I just don't see an advantage to a single table, but some apps like to have a dynamic way to generate lookup lists and won't create a new table for each one.

提交回复
热议问题