Home | Overview | How Do I | FAQ | Sample | Tutorial | ODBC Driver List
This article discusses how to examine the schema of a database — the structure of the database, as defined by its tables and their fields and indexes — at run time. While many applications are based on knowledge of the database schema at design time, there are situations in which you might need to determine the schema dynamically at run time:
See the MFC Database sample DAOVIEW for an example of this.
Perhaps users can add and delete tables and even alter the structure of tables by adding or deleting fields and indexes.
Dynamic examination of the schema is based on the use of DAO collections. A DAO database object contains the following collections: TableDefs, QueryDefs, Recordsets, and Relations. MFC exposes all of these via CDaoDatabase member functions except for the Recordsets collection. For details about how MFC exposes collections, see the articles DAO Collections and DAO Collections: Obtaining Information About DAO Objects.
The following illustration uses the TableDefs collection, but the principles demonstrated apply equally to the other collections.
To enumerate the TableDefs collection for a CDaoDatabase object
The MFC Database sample DAOVIEW performs these steps and lists the table names in a list control or a tree control. It then does the same thing for the fields and indexes in the tables and for the other collections in the database: QueryDefs and Relations.
See Also DAO: Where Is..., DAO Recordset, DAO Recordset: Binding Records Dynamically