![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
let's say you are designing a table with student data. one of the fields will be gender, which has a fairly constant set of possible values - male, female, hermaphrodite, unknown As such, should a "people_gender" table be created of type INT gender_id VARCHAR(40) gender_name or should there be an enum column in the student table with the 4 possible values? |
|
A larger more general question is: should you _ever_ use the enum data type? Why or why not? |
#3
| ||||
| ||||
|
|
I think that a special table for constraining gender values is overkill, and I would opt for setting the value directly in the student data table. |
|
A larger more general question is: should you _ever_ use the enum data type? Why or why not? The ISO SQL standard has ny ENUM data type, which makes it problematic. The standard way of doing it is using CHECK-constraints: CREATE TABLE students ( * * student_id INT NOT NULL PRIMARY KEY, * * gender VARCHAR(40) NOT NULL CHECK ( * * * * gender in ('male','female','hermaphrodite','unknown') * * ) ) |
|
x | +---+ a | +---+ |
|
x | +---+ c | +---+ |
#4
| |||
| |||
|
|
On 23 Feb, 19:54, Troels Arvin <tro... (AT) arvin (DOT) dk> wrote: [...] I think that a special table for constraining gender values is overkill, and I would opt for setting the value directly in the student data table. But then again, you might want to display gender in various languages. Gender is by the way described in http://en.wikipedia.org/wiki/ISO_5218. |
#5
| |||
| |||
|
|
The question is whether these different *representations* should go into the database. *For a TIMESTAMP you do not store the value in all formats that you need. |
|
*Space and performance is only one reason - the more important reason is that the user interfacing software must decided how to represent data. *The database should only store *properties* of entities. |
#6
| |||
| |||
|
|
On 25 Feb, 08:06, Robert Klemme <shortcut... (AT) googlemail (DOT) com> wrote: [...] The question is whether these different *representations* should go into the database. For a TIMESTAMP you do not store the value in all formats that you need. How is the representation of a timestamp relevant here? |
|
Space and performance is only one reason - the more important reason is that the user interfacing software must decided how to represent data. The database should only store *properties* of entities. How can the user interface figure out the name of something in a particular language? |
#7
| |||
| |||
|
|
For that typically resource files are used. *You only need some form of key from the DB but not the name of the gender. *In once case you might want to write the full name, in another place you want just an abbreviated name of the gender and in yet another place of the UI you use an icon. *All this is better handled outside the database. |
![]() |
| Thread Tools | |
| Display Modes | |
| |