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

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)
主站蜘蛛池模板: 甘泉县| 锡林郭勒盟| 本溪市| 台北市| 嘉善县| 蒙阴县| 永善县| 淮南市| 舒兰市| 龙里县| 苗栗市| 麻栗坡县| 平遥县| 婺源县| 黄浦区| 丹巴县| 海门市| 通化县| 甘洛县| 纳雍县| 苏尼特左旗| 酒泉市| 越西县| 绥德县| 星子县| 保德县| 濮阳县| 崇信县| 南汇区| 玉田县| 海南省| 鹤庆县| 伽师县| 佛山市| 盐亭县| 池州市| 囊谦县| 衡水市| 天门市| 白山市| 丰城市|