Database Reference
In-Depth Information
CHAPTER 10
Working with Metadata
10.0. Introduction
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 de‐
scribes 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:
Information about statement results
For statements that delete or update rows, you can determine how many rows were
changed. For a SELECT 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.
Information about databases and tables
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 ENUM or SET columns to generate web form elements
corresponding to the available choices.
Information about the MySQL server
The database server provides information about itself and about the status of your
current session with it. Knowing the server version can be useful for determining
whether it supports a given feature, which helps you build adaptive applications.
 
Search WWH ::




Custom Search