ENUM and SET

Both these field types are intended to represent a list of possible values; the difference is that the user can choose only one value from a defined list of values with ENUM, and more than one value with SET. With SET, the multiple values all go into one cell; multiple values do not imply the creation of more than one row of data.

We add a field named genre and define it as an ENUM. For now, we choose to put short codes in the value list, and one of them (F) as the default value:

In the value list, we have to enclose each value within single quotes, unlike in the default value field. In our design, we know that these values stand for Fantasy, Child, and Novel, but for now we want to see the interface's behavior with short codes. In the Insert panel, we now see a radio box interface:

If we decide to have more self-describing codes, we can go back to Structure mode and change the definition for the genre field. In the following example, we do not see the complete value list because the field is not large enough, but what we entered was 'Fantasy','Child','Novel'. We also have to change the default value to one of the possible values, to avoid getting an error message while trying to saving this file structure modification.

With the modified value list, the Insert panel now looks as follows:

Observe that the previous radio buttons have changed to a select list because of the longer size of the possible values.

If we want more than one possible value selected, we have to change the field type to SET. The same value list may be used, but now, using our browser's multiple value selector (usually control-click) we can select more that one value:

For the previous example, we would store only the genre codes in the books table in a normalized data structure, and would rely on another table to store the description for each code. In fact, we would not be using a SET or ENUM in this case.

Index Management

phpMyAdmin has a number of index management options, which we will cover in this section.

Single-Field Indexes

We have already seen how the Structure panel offers a quick way to create an index on a single field, thanks to some quick links like Primary, Index, and Unique. Under the field list, there is a section of the interface used to manage indexes:

This section has links to edit or delete every index. Here, the Field part lists only one field per index, and we can see that the whole field participates in the index.

We will now add an index on the title. However, we want to restrict the length of this index to reduce the space used by the on-disk index structure. The Create an index on 1 column option is appropriate, so we click Go. In the next screen, we specify the index details as shown in the following screen:

Here is how to fill this panel:

Index name: A name we invent
Index type: We can choose INDEX or UNIQUE
Field: We select the field that is used as the index, which is the title field
Size: We enter 30 instead of 100 (the complete length of the field) to save space

After saving this panel, we can confirm from the following screenshot that the index is created and does not cover the whole length of the title field:

 

<< Back to Part 2 | Continue to PhpMyAdmin Part Four >>

 

© Copyright 2003-2023 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.