Re: [PHP-DB] ENUM type

2001-01-15 Thread Alexey Borzov

Greetings, Cahyo!

At 15.01.01, 18:47, you wrote:
CSA> I don't know what is the benefit if we use ENUM type.
CSA> can everybody explain it?

It is an ugly crutch.

Well, you see, most RDBMSes will allow you to make a 'lookup
table' or 'dictionary' or something (dunno its official name).

Something like:

CREATE TABLE foo_baz_dictionary (
  baz integer not null primary key,
  baz_name char(50)
);

-- baz is a potential "enum" field
CREATE TABLE foo (
  bar integer,
  ...
  baz integer,
  foreign key (baz) references foo_baz_dictionary
);

Then when you insert something into 'foo', its 'baz' field is checked
against foo_baz_dictionary (which is far more manageable
than ENUM field definition).

MySQL does not support foreign keys and so its creators came up with ENUM
solution.


-- 
Yours, Alexey V. Borzov, Webmaster of RDW



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] ENUM type

2001-01-15 Thread Paul DuBois

At 9:49 PM +0700 1/15/01, Cahyo S. Aji wrote:
>I don't know what is the benefit if we use ENUM type.
>can everybody explain it?

Examples:

It looks like a character column, but it's represented as an integer,
so operations on it can be quite fast.  The numeric representation
also takes less space, in most cases.

By using it, you make the legal values for a column explicit in the
column definition.

You can look up the legal values for the column from within programs.
For example, you can parse SHOW COLUMNS LIKE 'col_name' output to get
the legal enumeration values, then use them to construct a set of
radio buttons or a popup menu in a web form. That way your form always
presents exactly the legal options for the column.

You can also use the column definition when validating submitted forms
to make sure the value submitted is legal.

-- 
Paul DuBois, [EMAIL PROTECTED]

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]