官术网_书友最值得收藏!

Building blocks of a T-SQL statement

When writing a T-SQL statement, the following three actions are required:

  1. Express the intended operation, such as reading or changing data
  2. Provide a target or source list of affected tables
  3. 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)
主站蜘蛛池模板: 临湘市| 汶上县| 邢台县| 肥乡县| 万安县| 禄丰县| 吴川市| 孟村| 遵化市| 杭州市| 万安县| 宜黄县| 邻水| 桃园市| 沙坪坝区| 太白县| 西青区| 林西县| 灵石县| 繁峙县| 米林县| 丹棱县| 兴隆县| 库车县| 龙陵县| 南丹县| 洪泽县| 井冈山市| 凤阳县| 丹巴县| 娄烦县| 上栗县| 斗六市| 周口市| 武强县| 荣昌县| 永登县| 怀安县| 南岸区| 合川市| 平阳县|