Current location: Hot Scripts Forums » Other Discussions » Database » To VARCHAR -or- To ENUM()


To VARCHAR -or- To ENUM()

Reply
  #1 (permalink)  
Old 07-16-09, 09:01 AM
in2mobi in2mobi is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
To VARCHAR -or- To ENUM()

I have a couple of database table in which I am wondering if it will be smarter to use ENUM() or VARCHAR. The information that will be stored in the fields will come from a html drop down list, so their are only so many possible answers. As of right now I am using ENUM() because it seems like it is a safer bet, but seeing as how the end user can only select an answer from a drop down list, I am thinking of switching the field to VARCHAR. One of my main concerns is how well does ENUM() fields carry over into other tables foreign keys. Any help on the positive and negatives of this move is greatly appreciated. Also, the database engine I am using for these tables is innodb, but I might also use some MYISAM tables. Thank You.

Last edited by in2mobi; 07-16-09 at 09:05 AM.
Reply With Quote
  #2 (permalink)  
Old 07-16-09, 10:42 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
The way I understand it is, the ENUM field can contain multiple values which will pertain to all records,
where a VARCHAR field contains only one value that can be unique for each record.

So if you are storing only one value (could be unique) into the field then VARCHAR would be much easier.
But if you are using the ENUM field to store multiple values to select from,
then replacing the ENUM field would require a separate table that contains the multiple values.
In which case an ENUM field would be more efficient.
Unless you want each record to have a different set of values associated with it.
Then a separate table would probably be needed.
__________________
Jerry Broughton
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
copying varchar to datetime badmullah Database 1 05-27-09 07:28 AM
using a form to create a new ENUM value in a MySQL database? Orid Database 2 03-07-07 02:32 PM
Help anyone ? phpfreek PHP 6 09-26-06 06:13 AM
ENUM, An easy way to tell mysql... nova912 Database 4 07-16-06 07:21 PM
Sorting a varchar column with numbers Programme PHP 7 09-09-05 02:57 AM


All times are GMT -5. The time now is 05:08 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.