473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

enum vs tinyint

For instance, there is one column has values 'New', 'Maintenance',
'Renovation', 'Not Specified', and which options below is better in
term of performance?

option 1.
set the column to tinyint unsigned not null, and store the value
1,2,3,4. The values 1,2,3,4 represent the values 'New', 'Maintenance',
'Renovation', 'Not Specified' respectively in another lookup table.
When i want to select a list of data, the sql is
"SELECT col1, colvalue FROM tbl1 LEFT JOIN tbl2 ON (tbl1.col1 =
tbl2.col2) LIMIT 0, 100".
tbl1 is main data table, tbl2 is lookup table, and both col1 and col2
column type is tinyint unsigned not null. colvalue column is 'New',
'Maintenance', 'Renovation', 'Not Specified'.

option 2
set the column to enum('n', 'm', 'r', 's'). The values 'n', 'm', 'r',
's' represent the values 'New', 'Maintenance', 'Renovation', 'Not
Specified' respectively in another lookup table. When i want to select
a list of data, the sql is
"SELECT col1, colvalue FROM tbl1 LEFT JOIN tbl2 ON (tbl1.col1 =
tbl2.col2) LIMIT 0, 100".
tbl1 is main data table, tbl2 is lookup table, and both col1 and col2
column type isenum('n', 'm', 'r', 's'). colvalue column is 'New',
'Maintenance', 'Renovation', 'Not Specified'.

Assume both the col1 and col2 are indexed

Thank you

Jul 23 '05 #1
1 5218
On 18 Feb 2005 01:16:24 -0800, in mailing.database.mysql
"bo*****@gmail.com" <bo*****@gmail.com> wrote:
| For instance, there is one column has values 'New', 'Maintenance',
| 'Renovation', 'Not Specified', and which options below is better in
| term of performance?
|
| option 1.
| set the column to tinyint unsigned not null, and store the value
| 1,2,3,4. The values 1,2,3,4 represent the values 'New', 'Maintenance',
| 'Renovation', 'Not Specified' respectively in another lookup table.
| When i want to select a list of data, the sql is
| "SELECT col1, colvalue FROM tbl1 LEFT JOIN tbl2 ON (tbl1.col1 =
| tbl2.col2) LIMIT 0, 100".
| tbl1 is main data table, tbl2 is lookup table, and both col1 and col2
| column type is tinyint unsigned not null. colvalue column is 'New',
| 'Maintenance', 'Renovation', 'Not Specified'.
|
| option 2
| set the column to enum('n', 'm', 'r', 's'). The values 'n', 'm', 'r',
| 's' represent the values 'New', 'Maintenance', 'Renovation', 'Not
| Specified' respectively in another lookup table. When i want to select
| a list of data, the sql is
| "SELECT col1, colvalue FROM tbl1 LEFT JOIN tbl2 ON (tbl1.col1 =
| tbl2.col2) LIMIT 0, 100".
| tbl1 is main data table, tbl2 is lookup table, and both col1 and col2
| column type isenum('n', 'm', 'r', 's'). colvalue column is 'New',
| 'Maintenance', 'Renovation', 'Not Specified'.
|
| Assume both the col1 and col2 are indexed
|


Use a modified option 2.
colvalue enum('New', 'Maintenance', 'Renovation', 'Not Specified')
default 'New'

No need for a second table.

http://dev.mysql.com/doc/mysql/en/enum.html

---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: moondaddy | last post by:
I'm bringing data from sql server into xml and one column is a tinyint data type in sql server. what's the equivalent of tinyint in xml? Thanks. -- moondaddy@nospam.com
2
by: Eugene | last post by:
Hi, In Query Analyzer: update tblUserProcess set usercode = 1002 Error: Arithmetic overflow error for data type tinyint, value = 1002. The statement has been terminated.
2
by: valmir cinquini | last post by:
Hi everybody I'm newbee in C# and I'm supporting an application where there's a method like following: public int addNews(DateTime dtNews, string strTitle, string strShortText, string...
2
by: tgif | last post by:
Can someone explain the format for converting a .NET datatype (such as string or int) to a database type (such as tinyint, datetime) for use in a SqlParameter.
0
by: Fabio Negri Cicotti | last post by:
I have created into the SQL Server 2 tables parent/child having the parent an autoincrement primary key. E.g.: Order table ordID - tinyint ordName - string(50) Order_Detail table ordID -...
0
by: Kenneth P | last post by:
Hi, In MySql db doc ch 11 TINYINT A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255. BIT BOOL BOOLEAN
0
by: Elmo Watson | last post by:
I am having all kinds of problems with a Stored Proc I'm trying to run, with the error I'm getting above. First - the way I'm reading it - the database EXPECTS a TinyInt - and it thinks I'm...
19
by: tshad | last post by:
I have a value in my sql table set to tinyint (can't set to bit). I am trying to move it into a boolean field in my program and have tried: isTrue = (int)dbReader and isTrue =...
21
by: Geoff Cox | last post by:
Hello I have a TINYINT(1) field, group1, in a mysql data base and the value is 1 but php if ($row == "1") { does not work. What should I be writing here?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.