Constructing an SQL Statement
ADO applications perform much of their database access by executing SQL statements. The form of these statements depends on the needs of the application. SQL statements can be constructed in the following ways:
- Hard-coded
- Constructed at run time
Hard-coded SQL statements are static statements performed by an application as a fixed task.
SQL statements constructed at run time enable the user to tailor the statement by using common clauses, such as SELECT, WHERE, and ORDER BY. This includes ad hoc queries entered by users.
The column list in a SELECT statement should contain only the columns needed to perform the current task. This reduces the amount of data sent over the network, and it reduces the effect of database changes on the application. For example, if an application does not reference a column from a table, the application is not affected by any changes made to that column.
Constructing SQL Statements for Cursors
The set of rows returned by a SELECT statement consists of all the rows that satisfy the conditions in the WHERE clause of the statement, and is known as the result set. Because ADO applications cannot always work effectively with the entire result set as a unit, they must use either ADO client-side cursors or SQL Server server-side cursors to work with a smaller subset of rows. For more information, see Cursors and Using Cursors with ADO.