
上QQ阅读APP看书,第一时间看更新
Building blocks of a T-SQL statement
When writing a T-SQL statement, the following three actions are required:
- Express the intended operation, such as reading or changing data
- Provide a target or source list of affected tables
- Provide a condition that filters the affected records
The intended operation is determined by the presence of the following clauses:
- The SELECT clause lists columns or expressions that will be displayed in the result set
- The DELETE, INSERT, or UPDATE clauses state the target table or view for these logical operations
As for the affected tables and filters, they are determined by the following clauses:
- The FROM clause lists the source tables, views and/or sub-queries that contain the data to be queried
- The WHERE clause states one or more conditions that will serve to filter the result set to the desired rows
The preceding clauses determine which data will be manipulated. The formatting of the results can be further modified by adding any of the following parts:
- The ORDER BY clause defines the order in which the rows will be returned
- The GROUP BY clause aggregates rows together based on the criteria provided (typically combined with aggregate functions in the SELECT clause)
- The HAVING clause applies a predicate to the results (different than the WHERE clause, which applies a predicate to the source rows)