Sunteți pe pagina 1din 2

SYSTEM CATALOG

Information about tables in the database is kept in the system


catalog (or the catalog). The catalog is maintained
automatically by the DBMS. When a user adds a new table,
changes the structure of an existing table,
or deletes a table, the DBMS updates the catalog to reflect
these changes.
This section describes the types of items kept in the catalog
and the way in which you can query it to
determine information about the database structure. (This
description represents the way catalogs are used
in a typical SQL implementation.) Although catalogs in
individual relational DBMSs will vary from the examples
shown here, the general ideas apply to most relational systems.
The catalog you will consider contains two tables: Systables
(information about the tables known to SQL)
and Syscolumns (information about the columns or fields within
these tables). An actual catalog contains
other tables as well, such as Sysindexes (information about the
indexes that are defined on these tables) and
Sysviews (information about the views that have been created).
Although these tables have many fields, only
a few are of concern here.
As shown in Figure 4-26, the Systables table contains the
Name, Creator, and Colcount fields. The Name
field identifies the name of a table, the Creator field identifies
the person or group that created the table, and
the Colcount field contains the number of fields in the table
being described. If, for example, the user named
Brown created the Rep table and the Rep table has nine fields,
there would be a row in the Systables table in
which the Name is Rep, the Creator is Brown, and the Colcount
is 9. Similar rows would exist for all tables
known to the system.
The Syscolumns table contains the Colname, Tbname, and
Coltype fields, as shown in Figure 4-27. The
Colname field identifies the name of a field in one of the tables.
The table in which the field is found is stored
in the Tbname field, and the data type for the field is found in
the Coltype field. There is a row in the Syscolumns
table for each field in the Rep table, for example. On each of
these rows, Tbname is Rep. On one

of these rows, Colname is RepNum and Coltype is CHAR(2). On


another row, Colname is LastName
and Coltype is CHAR(15).
Name Creator Colcount
A DBMS furnishes ways of using the catalog to determine
information about the structure of the database.
In some cases, this simply involves using SQL to query the
tables in the catalog. For example, to list the
name and type of all fields (columns) in the Part table, you
could use the following SQL command:
SELECT Colname, Coltype
FROM Syscolumns
WHERE Tbname= Part

NOTE
In MySQL, you use the SHOW TABLES command to produce a
list of all tables in the current database. The SHOW INDEX
command produces a list of all indexes. The SHOW COLUMNS
command, which consists of the words SHOW COLUMNS
FROM followed by the name of a table, produces details
concerning all columns in the indicated table. Running the
command
SHOW COLUMNS FROM CUSTOMER, for example, lists details
concerning all the columns in the Customer table.
NOTE
In Oracle, the equivalent tables for SYSTABLES, SYSCOLUMNS,
and SYSVIEWS are named DBA_TABLES,
DBA_TAB_COLUMNS, and DBA_VIEWS, respectively.
In other cases, special tools provide the desired documentation.
For example, Access has a tool called the
Documenter, which allows you to print detailed documentation
about any table, query, report, form, or other
object in the database. To document the objects in an Access
database, click the Database Tools tab, and
then click the Database Documenter button in the Analyze
group.

S-ar putea să vă placă și