Changing Table Structure

This chapter explores editing table definitions and using special column types. When developing Web applications (or any application), requirements often change because of new or modified needs. Developers must accommodate these changes through judicious table-structure editing.

Adding a Field

Suppose we need a new field to store a book's language, and by default, the books on which we keep data are written in English. We decide that the field will be called language, and will be a code composed of two characters (en by default).

In the Structure sub-page of the Table view for the books table, we can find the Add new field dialog. Here, we specify how many new fields we want and where the new fields go.

The positions of the new fields in the table only matter from a developer's point of view; we usually group the fields logically to find them more easily in the list of fields. The exact position of the fields will not play a role in the intended results (output from the queries), because these results can be adjusted regardless of the table structure. Usually, the most important fields (including the keys) are located at the beginning of the table, but this is a matter of personal preference.

In this case, we choose to put the new field At End of Table, which is the first choice in the menu, and click the Go button:

We then see the familiar panel for the new fields, repeated for the number of fields asked for. We fill it, and this time we put a default value, en. We then click on Save.

This panel appeared in horizontal mode, the default for $cfg['DefaultPropDisplay'].

Vertical Mode

If we set $cfg['DefaultPropDisplay'] to 'vertical', the panel to add new fields (along with the panel to edit a field's structure) will be presented in vertical order. The advantages of working in vertical mode become obvious especially when there are more choices for each field, as explained in Chapter 16 on MIME-Based Transformations.

Let's see how the panel appears if we are in vertical mode and ask for three new fields:

Editing Field Attributes

On the Structure sub-page, we can make further changes to our table. For this example, we have set $cfg['PropertiesIconic'] to 'both' to see both the icons along with their text explanation:

This panel does not allow every possible change to fields. It specifically allows:

> Changing one field structure, using the Change link on a specific field
> Removing a field: Drop
> Adding a field to an existing Primary key
> Setting a non-unique Index or a Unique index on a field
> Setting a Fulltext index (offered only if the field type allows it)

These are quick links that may be useful in specific situations. Keep in mind that they do not replace the full index management panel, or the full field structure panel. Both are explained in this chapter.

We can also use the checkboxes to choose fields, and with the appropriate With selected icons, Edit the fields or do a multiple field deletion with Drop. The Check All / Uncheck All option permits us to easily check or uncheck all boxes.


Continue to PhpMyAdmin Part Two >>


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