Daksh Pareek

Welcome to my personal portfolio website, showcasing my projects and blogs.

Too late to understand enums in database?

2024-12-12


So today in one of the discussion, which is related to database schema, my TL mentioned that “do not use enums here”. I agreed and said yes. I will not do it; this is just for demonstration purpose. Later in the day I got a flashback when my previous TL said the same, that do not use enums in database and use string instead.

I never gave it a thought before. I used to just go ahead with instructions, but now I wanted to know why. So, I chatted with LLM to find out the truth behind this practice.

I learned that an enum is a datatype defined at the database level, and it is not only a string. They are named values called elements, members. This was new to me. I never paid attention to this in 9 years of my programming journey. But it’s never too late.

An enum is a type in database that allows us to restrict a column to accept only a predefined set of values.

So why do some developers avoid them?

When to use enum?

Conclusion

We are told to avoid enums because we want flexibility, ease of maintainance and simplicity in deployment process. Enums do provide us strong data integrity at database level but they can introduce complexity and rigidity that may not be desirable in current project.


Writing Improvement Tips For Self