Most of the SQL statements used so far have been written to work with the data stored in the database. That is, after all, what the database is designed to hold. But sometimes you need more than just data values. You need information that characterizes or describes those values—that is, the statement metadata. Metadata is used most often to process result sets, but also applies to other aspects of your interaction with MySQL. This chapter describes how to obtain and use several types of metadata:
For statements that delete or update rows, you can determine how many
rows were changed. For a
statement, you can obtain the number of columns in the result set,
as well as information about each column in the result set, such as
the column name and its display width. For example, to format a
tabular display, you can determine how wide to make each column and
whether to justify values to the left or right.
A MySQL server can be queried to determine which databases and tables it
manages, which is useful for existence tests or producing lists. For
example, an application might present a display enabling the user to
select one of the available databases. Table metadata can be
examined to determine column definitions; for example, to determine
the legal values for
SET columns to generate web form
elements corresponding to the available choices.