Sei sulla pagina 1di 2

Accessing and Changing Relational Data (SQL Server 2000)

Parts of a SELECT Statement


The full syntax of the SLCT state!ent is co!"lex# $ut the !ain clauses can $e su!!ari%ed as&
SLCT select_list
'()T* new_table_name+
,R*- table_list
'./R search_conditions+
'0R*12 34 group_by_list+
'/A5()0 search_conditions+
'*RDR 34 order_list 'ASC 6 DSC+ +
select_list
Descri$es the colu!ns of the result set7 (t is a co!!a8se"arated list of ex"ressions7 ach ex"ression
defines $oth the for!at (data ty"e and si%e) and the source of the data for the result set colu!n7 ach
select list ex"ression is usually a reference to a colu!n in the source ta$le or vie9 the data is co!ing
fro!# $ut can $e any other ex"ression# such as a constant or a Transact8SQL function7 1sing the :
ex"ression in a select list s"ecifies that all colu!ns in the source ta$le are returned7
()T* new_table_name
S"ecifies that the result set is used to create a ne9 ta$le7 new_table_name s"ecifies the na!e of the
ne9 ta$le7
,R*- table_list
Contains a list of the ta$les fro! 9hich the result set data is retrieved7 These sources can $e&

3ase ta$les in the local server running -icrosoft; SQL Server<7

5ie9s in the local SQL Server7 SQL Server internally resolves a vie9 reference to references
against the $ase ta$les that !a=e u" the vie97

Lin=ed ta$les# 9hich are ta$les in *L D3 data sources !ade accessi$le to SQL Server7 This is
called a distri$uted >uery7 *L D3 data sources can $e accessed fro! SQL Server $y lin=ing
the! as a lin=ed server# or referencing the data source in an *2)R*.ST or *2)Q1R4
function7
The ,R*- clause can also contain ?oin s"ecifications# 9hich define the s"ecific "ath SQL Server
is to use in navigating fro! one ta$le to another7
The ,R*- clause is also used on the DLT and 12DAT state!ents to define the ta$les that
are !odified7
./R search_conditions
The ./R clause is a filter that defines the conditions each ro9 in the source ta$les !ust !eet to
>ualify for the SLCT7 *nly ro9s that !eet the conditions contri$ute data to the result set7 Data fro!
ro9s that do not !eet the conditions are not used7
The ./R clause is also used on the DLT and 12DAT state!ents to define the ro9s in the target
ta$les that are !odified7
0R*12 34 group_by_list
The 0R*12 34 clause "artitions the result set into grou"s $ased on the values in the colu!ns of the
group_by_list7 ,or exa!"le# the Northwind Orders ta$le has three values in ShipVia7 A 0R*12 34
ShipVia clause "artitions the result set into three grou"s# one for each value of ShipVia7
/A5()0 search_conditions
The /A5()0 clause is an additional filter that is a""lied to the result set7 Logically# the /A5()0 clause
filters ro9s fro! the inter!ediate result set $uilt fro! the a""lication of any ,R*-# ./R# or 0R*12
34 clauses in the SLCT state!ent7 /A5()0 clauses are !ost co!!only used 9ith a 0R*12 34 clause#
although a 0R*12 34 clause is not re>uired $efore a /A5()0 clause7
*RDR 34 order_list ' ASC 6 DSC +
The *RDR 34 clause defines the order in 9hich the ro9s in the result set are sorted7 order

Potrebbero piacerti anche