MySQL Forums
Forum List  »  Newbie

Re: Cannot get ENUM to work,
Posted by: Phillip Ward
Date: February 09, 2015 07:58AM

Just to add to the mix, I would offer a word of caution regarding Enums.
For a short list like this - three states, unlikely to change - you'll probably get away with it but for any "Real World" application, I'd recommend using a "lookup table" instead; a "real" table with one row per option. Changing the values in such a table is a simple "data" change that can be done easily (say, within your application). Changing an Enum needs you (the DBA) to make a more significant (i.e. risky) changes to the table definition. OK, that may not seem like a Big Thing, but when somebody rings you at some un-Godly hour of the morning because they really, really have to add another option to that [Enum] list, then it will suddenly feel like a Big Thing.

create table answers 
( id varchar( 1 ) not null 
, text varchar( 20 ) not null 
, primary key ( id ) 
); 

create table users 
( id int auto_increment not null 
, name varchar( 40 ) not null 
, question_answer  varchar( 1 ) 
, primary key ( id )
, foreign key ( question_answer ) reference answers( id ) 
); 

insert into answers values( 'Y', 'Yes' ), ( 'N', 'No' ), ( 'S', 'Not Sure' ); 

insert into users ( name, question_answer ) values ( 'Fred', 'Y' ); 

insert into answers values( 'A', 'Prefer not to Answer' );

Regards, Phill W.

Options: ReplyQuote


Subject
Written By
Posted
February 06, 2015 03:21PM
February 07, 2015 03:15PM
February 07, 2015 04:30PM
February 07, 2015 01:13PM
February 07, 2015 01:38PM
Re: Cannot get ENUM to work,
February 09, 2015 07:58AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.