Database design - relations vs properties code example

Example: Database design - relations vs properties

create table users (
  user_id bigint unsigned not null auto_increment primary key,
  name varchar(255) not null,
  description varchar(255),
  marital_status enum('single', 'married'),
  favorite_color enum('red', 'green', 'blue'),
  hobby1 enum('painter', 'doctor', 'lawyer'),
  hobby2 enum('painter', 'doctor', 'lawyer'),
  hobby3 enum('painter', 'doctor', 'lawyer')
);


You want to avoid extra tables and joins unless really needed. This is exactly what enums are for. enums internally store as integer and in usage look like strings with constrained values.

Tags:

Misc Example