Jump to content

[SOLVED] Which datatype would be better?


Yesideez

Recommended Posts

I've got a large database and one particular table lists music events in my area (it's called "events)

 

There is a field in that table called "type" which I'm using to describe what type of event it is like dance, private, trance, techno etc. and the list is quite long, about 15 types.

 

There's another field called "status" which tells me the status of the event, "Disabled" meaning it is withdrawn from public view, "Active" meaning public can view it, "Postponed" meaning it has been postponed, just 3 selections.

 

I also have a third field called "modded" which tells me if a moderator has checked the event. Events can be added by the public so moderators need to check them for content and more. This field contains "Waiting" when an event is newly added, "Safe" when a moderator has OK'd it or "Unsafe" if a moderator has checked it and refuses it for whatever reason.

 

Now so far for the "type" field it's a number which is used to reference another table because a) I'm using a drop-down box when users add events and b) I may need to add new event types in the future. My scripts build the drop-down boxes automatically when adding data and as I add new event types I don't have to change anything else apart from just add another record to the table.

 

Now the real query is with the "status" and "modded" fields.

 

Is it better to use them the same as "types" or as an integer (eg. 1=Waiting, 2=Safe etc.) or as an ENUM?

 

I'm not sure how fast ENUM datatypes are when running a SELECT query. I understand searching for matching integers is faster and more efficient than searching for matching VARCHAR types.

 

Apologies for the size of this post but I really can't get my head around using JOIN in the slightest and when running a SELECT query sometimes I need to search for data matching on various event content, status and modded in different combinations depending on circumstances.

 

Oh, to make matters worse I've also got another table called "users" which contains obvious (haha) information so I also need to pull the username from the users table when listing events as I need to show who added the event as well as the name of the moderator who verified the event.

Link to comment
Share on other sites

Have you read through the docs here: http://dev.mysql.com/doc/refman/5.1/en/enum.html

 

You're right that using integers and a join is more flexible.  Changing the enum requires changing the table definition.

 

As for speed, I wouldn't expect much difference.. but as always, you should benchmark it if it's really important.

 

As for joins.. the enum has the advantage of not confusing you as much :)  On the other hand, joins are important to understand for using databases.  Maybe it's good to learn about them in a simple context like this.  Joining in the way that you are for the types is the simplest kind of join there is.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.