Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • Thank you for your answer. So if in the future I need to add a few more columns to extend functionality, it would still be better then EAV? For instance, if a table has 1 million records, adding 5 optional fields to the events table will add 5 million empty fields to the database. Using EAV would add 0 empty fields. This is the only concern I have. Do you think even in this situation it would still be better to add columns to the appropriate table then to just add a event_meta table? Commented Aug 6, 2014 at 15:58
  • @alwaysStuck If you want to use relational databases, you should adhere to normal forms. If you want to use no-sql databases, that are key-value-based, non relational type of databases, you can do as you are proposing here. Also a great number of optional fields in an entity is a bad design, indicating an extra entity is needed. For example a doctor-guild-number in the person table will be empty for almost everyone, a doctor-table with a one-one relationship with person should hold all attributes only applicable to doctors. Commented Aug 6, 2014 at 16:07
  • 1
    @alwaysStuck: There's nothing wrong with using a SQL database table as a Key/Value store or EAV, if Key/Value or EAV are the right tools for the task. Commented Aug 6, 2014 at 16:44
  • 1
    @alwaysStuck -- one thing we've used successfully for things like this would be to have an extra metadata field that is just a serialized object. The key caveat there is it works great if you never, ever need to query on the contents. Commented Aug 6, 2014 at 16:54
  • @alwaysStuck: existing table rows are not modified when a new column is added to the table. Commented Aug 6, 2014 at 16:59