Pogledajte određenu poruku
Staro 21. 01. 2006.   #5
dinke
Super Moderator
Invented the damn thing
 
Avatar dinke
 
Datum učlanjenja: 06.06.2005
Poruke: 2.371
Hvala: 370
701 "Hvala" u 194 poruka
dinke je pravi dragi kamendinke je pravi dragi kamendinke je pravi dragi kamendinke je pravi dragi kamendinke je pravi dragi kamendinke je pravi dragi kamendinke je pravi dragi kamen
Default

Citat:
Originalno napisao Ilija Studen
ENUM je u suštini VARCHAR koji ima filter (tj. ne dozvoljava insertovanje nedefinisane vrednosti). Bolje je koristiti numeričke tipove i tipove fiksne širine gde je to moguće zbog performansi - manje prostora zauzimaju, indeksi su lakši itd.
Manual nije bas jasan oko toga, ali evo sta kaze Paul DuBois (MySQL 3rd Edition)
Citat:
ENUM and SET are classified as string types because enumeration and set members are specified as strings when you create columns of these types. However, the ENUM and SET types actually have a split personality: The members are stored internally as numbers and you can work with them as such. This means that ENUM and SET types are more efficient than other string types because they often can be handled using numeric operations rather than string operations.

MySQL sequentially numbers ENUM members in the column definition beginning with 1. (The value 0 is reserved for the error member, which is represented in string form by the empty string.) The number of enumeration values determines the storage size of an ENUM column. One byte can represent 256 values and two bytes can represent 65,536 values. (Compare this to the ranges of the one-byte and two-byte integer types TINYINT UNSIGNED and SMALLINT UNSIGNED.) Thus, counting the error member, the maximum number of enumeration members is 65,536 and the storage size depends on whether there are more than 256 members. You can specify a maximum of 65,535 (not 65,536) members in the ENUM definition because MySQL reserves a spot for the error member as an implicit member of every enumeration. When you assign an illegal value to an ENUM column, MySQL assigns the error member. (In strict mode, an error occurs instead.)

Here's an example you can try using the mysql client. It demonstrates that you can retrieve ENUM values in either string or numeric form (which shows the numeric ordering of enumeration members and also that the NULL value has no number in the ordering):

mysql> CREATE TABLE e_table (e ENUM('jane','fred','will','marcia'));
mysql> INSERT INTO e_table
-> VALUES('jane'),('fred'),('will'),('marcia'),(''),( NULL);
mysql> SELECT e, e+0, e+1, e*3 FROM e_table;
+--------+------+------+------+
| e | e+0 | e+1 | e*3 |
+--------+------+------+------+
| jane | 1 | 2 | 3 |
| fred | 2 | 3 | 6 |
| will | 3 | 4 | 9 |
| marcia | 4 | 5 | 12 |
| | 0 | 1 | 0 |
| NULL | NULL | NULL | NULL |
+--------+------+------+------+
Prema tome mislim da je enum('0','1') pravo resenje za tvoj problem.
__________________
Caught in a Web|Blogodak
With great power comes great responsibility!
dinke je offline   Odgovorite uz citat