目录数据的用法Uses of Catalog Data

应用程序以各种方式使用目录数据。Applications use catalog data in a variety of ways. 下面是一些常见用途:Here are some common uses:

  • 在运行时构造 SQL 语句。Constructing SQL statements at run time. 垂直应用程序(如订单输入应用程序)包含硬编码的 SQL 语句。Vertical applications, such as an order entry application, contain hard-coded SQL statements. 应用程序使用的表和列提前固定,这与访问这些表的语句是一样的。The tables and columns that are used by the application are fixed ahead of time, as are the statements that access these tables. 例如,订单输入应用程序通常包含一个参数化 INSERT 语句,用于向系统添加新订单。For example, an order entry application usually contains a single, parameterized INSERT statement for adding new orders to the system.

    一般应用程序(如使用 ODBC 检索数据的电子表格程序)通常在运行时基于用户输入构造 SQL 语句。Generic applications, such as a spreadsheet program that uses ODBC to retrieve data, often construct SQL statements at run time based on input from the user. 此类应用程序可能要求用户键入要使用的表和列的名称。Such an application could require the user to type the names of the tables and columns to use. 但是,如果应用程序显示的表和列的列表与用户可从中进行选择的表和列的列表,则用户会更容易。However, it would be easier for the user if the application displayed lists of tables and columns from which the user could make selections. 若要生成这些列表,应用程序将调用 SQLTablesSQLColumns 目录函数。To build these lists, the application would call the SQLTables and SQLColumns catalog functions.

  • 在开发过程中构造 SQL 语句。Constructing SQL statements during development. 应用程序开发环境通常允许编程人员在开发程序时创建数据库查询。Application development environments typically allow the programmer to create database queries while developing a program. 然后在生成的应用程序中对查询进行硬编码。The queries are then hard-coded in the application being built.

    此类环境还可以使用 SQLTablesSQLColumns 来创建程序员可从中进行选择的列表。Such environments could also use SQLTables and SQLColumns to create lists from which the programmer could make selections. 这些环境还可以使用 SQLPrimaryKeysSQLForeignKeys 来自动确定和显示所选表之间的关系,并使用 SQLStatistics 来确定和突出显示索引字段,以便程序员可以创建高效的查询。These environments might also use SQLPrimaryKeys and SQLForeignKeys to automatically determine and show relationships between selected tables, and use SQLStatistics to determine and highlight indexed fields so the programmer can create efficient queries.

  • 构造游标。Constructing cursors. 提供可滚动的游标引擎的应用程序、驱动程序或中间件可以使用 SQLSpecialColumns 来确定唯一标识行的一列或多列。An application, driver, or middleware that provides a scrollable cursor engine could use SQLSpecialColumns to determine which column or columns uniquely identify a row. 该程序可以为已提取的每行生成一个包含这些列的值的 键集The program could build a keyset containing the values of these columns for each row that has been fetched. 当应用程序向后滚动到行时,它将使用这些值来提取行的最新数据。When the application scrolls back to the row, it would then use these values to fetch the most recent data for the row. 有关可滚动游标和键集的详细信息,请参阅可 滚动游标For more information about scrollable cursors and keysets, see Scrollable Cursors.