mysql field types : ENUM, SET

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

mysql field types : ENUM, SET

Post by mudkicker »

hi mates,
just wanna ask about these two field types :

where should i use them and how? i read the mysql manual but can't get a good info about it..
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

obviously, enum are used when you have column with enumerable allowed values ;)

f.e. I have log table in my db, which contains log entries for my web app. It has 'type' column of type enum with allowed values: fatall,warning,note eg each record has some type, either fatal, warning or note.

There is another column, status of type set with allowed values: read, sent, flagged eg each record can be sent and/or read and/or flagged.

It might be not the best example, but it works for me...
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

ok thanks weirdan,
if it's so, does it make any difference?

fore example i want to you ise for a yes or no question sotred in db.
i mean i ask in form, if user needs a picture. if yes it will be stored for yes or no.

if there's no difference between using set,enum etc. or doin it wit 0,1 (1 if yes)...
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

There's no real difference other than the fact it's easier to read "yes", "no" than 1,0 (especially if you have lots more options than that). From MySQL's point of view - an enum is extremely fast because it knows the allowed values already, so bare that in mind too.
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

hmm. thanks people i got it!
Post Reply