As its name implies, a QueryDef object is the definition of a query, either saved permanently in a Microsoft Jet database, or created as a temporary object. A QueryDef object doesn’t contain any data or perform an action; it’s merely the set of instructions Microsoft Jet uses to select information or perform an action, such as the deletion or insertion of records in a database table.
Not everything that can be stored in a QueryDef object is what is usually thought of as a “query.” In addition to SQL SELECT statements, which select, join, and order information from one or more tables, a QueryDef object can contain an SQL DELETE, INSERT, or CREATE TABLE statement.
Some QueryDef objects return their results in the form of a set of records. These objects perform similarly to what are known as views in other relational database systems. You can create an SQL statement and save it as a permanent QueryDef object in a database, and then use that QueryDef object as if it were a table. You can update it or join it to another table or QueryDef object.
Other QueryDef objects can perform an action, such as running an SQL DELETE statement, or modify the database structure, such as the CREATE TABLE statements used throughout this chapter. A special form of the QueryDef object, known as a pass-through query, is used to communicate directly with an ODBC database such as SQL Server or Oracle. The contents of a pass-through QueryDef object are not evaluated by Microsoft Jet, but are passed through to the ODBC database, which then interprets the text contained in the SQL property of the QueryDef object.
See Also For a full discussion of how to use the various forms of QueryDef objects and how to optimize their performance, see Chapter 4, “Queries.” For more information about creating and using pass-through queries, see Chapter 9, “Developing Client/Server Applications.”
This section covers how to create and manipulate QueryDef objects in a database.
Note that a QueryDef object can be created only in a native Microsoft Jet database. A QueryDef object can’t be stored in a FoxPro or SQL Server database, for example.
There is no SQL DDL statement that can be used to create permanent QueryDef objects. All QueryDef objects must be created either interactively, through a product such as Microsoft Access, or programmatically by using DAO.