Shmuli
Shmuli

Reputation: 155

Enum in a database

I want to have an attribute in a table that I want to be able to update. What is the best way to implement it?

  1. to use a data type "Enum"
  2. to create a second table with the enum values and in the main table I will keep a enum_ID to the second table. And when I will want to add or update en enum value, I will just need to to update the specific row or delete or add?

Im using MySql

Upvotes: 0

Views: 52

Answers (1)

Christian P
Christian P

Reputation: 12240

Second choice if better when want to update your attribute values. When your doing the update / insert of the new attribute, Id of the attribute in the master table remains the same. You only need to do INSERT or UPDATE on your attributes table to add/change attributes.

If you go with the first choice and use ENUM data type, you will need to do ALTER TABLE every time you need to insert or update your attributes and you will need do an UPDATE in the main table for every ENUM value that changed.

Upvotes: 1

Related Questions