Vous êtes sur la page 1sur 145

In 7bis Cbapter

I DeveIopment Studio
AnaIysis Services and Cubes
Mlcrosolt Analysls
Scrvlccs
Cbapter 23
Copyright 2008 by The McGraw-Hill Companies. Click here for terms of use.
566 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
M
icrosolt Analysis Scrviccs is a group ol scrviccs that is uscd to managc data
that is storcd in a data warchousc or data mart. Analysis Scrviccs organizcs
data lrom a data warchousc into multidimcnsional cubcs (scc Chaptcr 22)
with aggrcgatcs to allow thc cxccution ol sophisticatcd rcports and complcx qucrics.
Thc kcy lcaturcs ol Analysis Scrviccs arc
asc ol usc
Flcxiblc data modcl
Scvcral supportcd AP!s
Analysis Scrviccs ollcr wizards lor almost cvcry task that is cxccutcd during thc
dcsign and implcmcntation ol a data warchousc. For cxamplc, ata Sourcc Vizard
allows you to spccily onc or morc data sourccs, whilc Cubc Vizard is uscd to crcatc a
multidimcnsional cubc whcrc aggrcgatc data is storcd.
asc ol usc is guarantccd by 8usincss !ntclligcncc (8!) cvclopmcnt Studio. You
can usc this tool to dcvclop databascs and othcr data warchousing objccts. This mcans
that 8! cvclopmcnt Studio ollcrs onc intcrlacc lor dcvcloping both Analysis Scrviccs
projccts and SQL Scrvcr !ntcgration Scrviccs and Rcporting Scrviccs projccts.
!n contrast to most othcr data warchousing systcms, Analysis Scrviccs allows you to
usc thc architccturc that is most appropriatc lor a spccilic data warchousing systcm. You
can choosc bctwccn thc thrcc architccturcs (MLAP, RLAP, and HLAP), which
arc discusscd in dctail in thc prcvious chaptcr.
I DeveIopment Studio
Thc main componcnt ol Analysis Scrviccs is 8usincss !ntclligcncc cvclopmcnt Studio,
a managcmcnt tool that providcs onc dcvclopmcnt platlorm lor !ntcgration Scrviccs,
Rcporting Scrviccs data mining, and Analysis Scrviccs. 8uilt on \isual Studio, 8!
cvclopmcnt Studio supports an intcgratcd dcvclopmcnt platlorm lor systcm dcvclopcrs
in thc busincss intclligcncc arca. cbugging, sourcc control, and codc dcvclopmcnt arc
availablc lor all componcnts ol thc 8! application.
You can usc 8! cvclopmcnt Studio not only to crcatc and managc cubcs, but also
to dcsign capabilitics lor SQL Scrvcr Rcporting Scrviccs and SQL Scrvcr !ntcgration
Scrviccs. (Rcporting Scrviccs is discusscd in Chaptcr 25, whilc !ntcgration Scrviccs is
bcyond thc scopc ol this book.)
Cha pt er 2 3: Mi c r os of t Ana l ys i s S er v i c es 567
|e ase/ |s|e//c:e c/ 3| |e|e|c(mes| :|a1|c |s |e/, s|m||c/ |c ||e |s|e//c:e c/ :9| :e/|e/ /cscemes| :|a1|c.
|cae|e/, ||ese |ac |cc|s 1|//e/ |s ||e|/ 1e(|c,mes|. ,ca s|ca|1 ase 3| |e|e|c(mes| :|a1|c |c 1e|e|c( 3| (/c(e:|s,
a|||e ,ca s|ca|1 ase :9| :e/|e/ /cscemes| :|a1|c mc|s|, |c c(e/c|e cs1 mc|s|c|s 3| 1c|c|cse c|(e:|s.
!n this chaptcr, 8! cvclopmcnt Studio is uscd to crcatc a cubc bascd upon thc
AdventureWorksDW databasc and to proccss it. To start 8! cvclopmcnt Studio, click
Start, All Programs, Microsoft SQL Server 2008, and linally SQL Server Business
ntelligence Development Studio.
Creating a New Project
Thc lirst stcp in building an analytic application is to crcatc a ncw projcct. To build a projcct
click Iile, sclcct New, and choosc Project. !n thc New Project dialog box (scc Figurc 231),
click thc Business ntelligence Projects loldcr in thc Project Types panc. !n thc Templates
panc, sclcct Analysis Services Project. Typc thc namc ol thc projcct and its location in thc
Name and Location tcxt boxcs, rcspcctivcly. For purposcs ol this cxamplc, namc thc projcct
Project1, as shown in Figurc 231. Thc ncw projcct will bc crcatcd altcr you click OK.
||qcre 11-1 |e |ea |/c(e:| 1|c|c |cs
568 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Thc ncw projcct is always crcatcd in a ncw solution. Hcncc, thc solution is thc largcst
managcmcnt unit in 8! cvclopmcnt Studio, and always compriscs onc or morc projccts.
(!l thc Solution xplorcr panc, which allows you to vicw and managc objccts in a solution
or a projcct, is not visiblc, you can vicw it by clicking View in thc mcnu bar and sclccting
Solution Explorer.)
Takc a look at thc Solution Explorer panc with thc ncwly crcatcd projcct. 8cncath
thc projcct nodc thcrc arc thc lollowing loldcrs, among othcrs:
Data Sources Storcs thc inlormation lor connccting to thc sourcc databasc.
Data Source Views Contains inlormation conccrning thc subsct ol tablcs in a
sourcc databasc.
Cubes Compriscs all cubcs that bclong to thc projcct.
Dimensions Contains all dimcnsions. Analysis Scrviccs supports thrcc typcs ol
dimcnsions. Shared dimensions (also callcd conlormcd dimcnsions) arc dimcnsions
that arc sharcd among two or morc cubcs in thc databasc. Typical sharcd dimcnsions
arc Time, Product, and Customer. Pri.ate dimensions arc crcatcd lor an individual
cubc. A linked dimension is bascd on a dimcnsion that is storcd in anothcr Analysis
Mining Structures Allows you to crcatc a data mining modcl using thc ata
8csidcs thcsc loldcrs, thcrc arc scvcral othcr loldcrs (Rolcs, Asscmblics, and
Misccllancous). Thc dcscription ol thcsc loldcrs can bc lound in 8ooks nlinc.
ncc thc projcct is crcatcd, you should crcatc a data sourcc.
Creating a Data Source
To crcatc a data sourcc, rightclick thc Data Sources loldcr in thc Solution Explorer
panc and sclcct New Data Source. Thc Data Source Wizard appcars, which guidcs
you through thc proccss ol crcating a data sourcc. (This cxamplc uscs thc SQL Scrvcr
samplc databasc callcd AdventureWorksDW as thc data sourcc.)
First, on thc Select how to define the connection pagc, makc surc that thc Create a
data source based on an existing or new connection radio button is choscn and click
New. !n thc Connection Manager dialog box, sclcct Native OLE DB/SQL Server
Native Client 10.0 and sclcct thc namc ol your databasc scrvcr as thc scrvcr namc. !n
thc samc stcp, choosc Use Windows Authentication and, lrom thc Select or enter a
database name dropdown list, choosc thc AdventureWorksDW databasc. 8clorc you
click OK, click thc Test Connection button to tcst thc conncction to thc databasc.
Cha pt er 2 3: Mi c r os of t Ana l ys i s S er v i c es 569
Finally, on thc Completing the Wizard pagc, givc thc ncw data sourcc a namc
(lor this cxamplc, call it Source1) and click Iinish. Thc ncw data sourcc appcars in thc
Solution Explorer panc in thc Data Sources loldcr (scc Figurc 232).
Thc ncxt stcp is to crcatc a vicw that corrcsponds to thc sclcctcd data sourcc.
Creating a Data Source View
A data sourcc vicw is uscd to dclinc thc schcma inlormation you want to usc in your
solution. !n othcr words, a data sourcc vicw contains inlormation conccrning thc subsct ol
tablcs lrom thc spccilicd sourcc databasc. (You should crcatc a data sourcc vicw whcn your
databasc compriscs hundrcds ol tablcs, ol which only a lcw arc usclul in a 8! application.)
To crcatc such a vicw, rightclick thc Data Source Views loldcr in thc Solution
Explorer panc and sclcct New Data Source View. Thc Data Source View Wizard
guidcs you through thc stcps that arc ncccssary to crcatc a data sourcc vicw. (This
cxamplc crcatcs a vicw callcd View1, which is bascd upon thc Customer and Project
tablcs as wcll as thcir rclatcd tablcs.)
First, on thc Select a Data Source pagc, sclcct an cxisting rclational data sourcc (lor this
cxamplc, sclcct Source1) and click Next. n thc ncxt pagcSelect Tables and Views
you sclcct tablcs that bclong to your cubc cithcr as dimcnsion tablcs or lact tablcs.
(To sclcct a tablc, mark its namc and click thc ~ button in thc middlc ol thc window.
Again, click Finish. Altcr that, thc tablc appcars in thc ncluded objects panc.) For this
cxamplc, sclcct thc customer and product tablcs lrom thc AdventureWorksDW databasc.
Thcsc tablcs arc callcd DimCustomer and DimProduct, rcspcctivcly, and will bc uscd to
build cubc dimcnsions. Also, by clicking thc Add Related Tables button, you instruct thc
systcm to lind tablcs that arc rclatcd to thc two sclcctcd tablcs. (To lind rclatcd tablcs, thc
systcm scarchcs all primary kcy/lorcign kcy rclationships that cxist in thc databasc.)
||qcre 11-1 |e :c|a||cs |s(|c/e/ (cse a||| sea 1c|c sca/:e
570 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Also add thc DimTime tablc, bccausc thc timc dimcnsion is (almost) always a part
ol a cubc. Altcr that, click Next. n thc Completing the Wizard pagc, thc systcm
shows thc tablcs, which you can scc in scc Figurc 233:
imCustomcr
imProduct
FactRcscllcrSalcs
imProductSubcatcgory
Fact!ntcrnctSalcs
imTimc
Click Finish. Altcr thc tablcs arc sclcctcd, thc wizard is complctcd and ata Sourcc
\icw csigncr shows thc sclcctcd tablcs (scc Figurc 234). (ata Sourcc \icw csigncr is
a tool that is uscd to show a graphical rcprcscntation ol thc data schcma you havc dclincd.)
ata Sourcc \icw csigncr ollcrs scvcral usclul lunctions. To inspcct thc objccts
you havc in your sourcc vicw, movc your mousc pointcr to thc crossarrow icon in thc
bottomright corncr. Vhcn thc pointcr changcs to a crossarrow icon, click thc icon.
Thc Navigation window appcars. Now you can navigatc lrom onc part ol thc diagram
to anothcr part. (!l you want to lind a spccilic tablc, usc thc Data Source View lunction
||qcre 11-1 |e tcm(|e||s ||e |cc/1 (ce
Cha pt er 2 3: Mi c r os of t Ana l ys i s S er v i c es 571
in thc mcnu bar and sclcct Iind Table.) To vicw thc data in a tablc, rightclick thc tablc
and thcn click Explore Data.
You can also crcatc namcd qucrics, which arc qucrics that arc pcrsistcntly storcd and
thcrclorc can bc acccsscd likc any tablc. To crcatc such a qucry, click thc Data Source
View lunction in thc mcnu bar and thcn sclcct thc New Named Query icon. Thc Create
Named Query dialog box allows you to crcatc any qucry in rclation to sclcctcd tablcs.
AnaIysis Services and Cubes
A cube is a multidimcnsional structurc that contains all or a part ol thc data lrom a data
warchousc. ach cubc contains thc lollowing componcnts:
imcnsions
Mcmbcrs
Hicrarchics
Cclls
||qcre 11-4 |c|c :ca/:e l|ea |es|se/ a||| ||e se|e:|e1 |c||es
572 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Lcvcls
Propcrtics
A dimension is a sct ol logically rclatcd attributcs (storcd togcthcr in a dimcnsional
tablc) that closcly dcscribcs mcasurcs (storcd in thc lact tablc). Although thc tcrm "cubc"
implics thrcc dimcnsions, a multidimcnsional cubc gcncrally can havc many morc
dimcnsions. For instancc, Time, Product, and Customer arc thc typical dimcnsions that
arc part ol many modcls.
0se |m(c/|cs| 1|mess|cs c/ c :a|e |s ||e eesates 1|mess|cs, a||:| |s:|a1es c|| mecsa/es 1e/|se1 |s ||e
/c:| |c||e.
ach discrctc valuc in a dimcnsion is callcd a member. For instancc, thc mcmbcrs
ol a Product dimcnsion could bc Computcrs, isks, and CPUs. ach mcmbcr can bc
calculatcd, mcaning that its valuc is calculatcd at run timc using an cxprcssion that is
spccilicd during thc dclinition ol thc mcmbcr. (8ccausc calculatcd mcmbcrs arc not
storcd on thc disk, thcy allow you to add ncw mcmbcrs without incrcasing thc sizc ol
a corrcsponding cubc.)
Hierarchies spccily groupings ol multiplc mcmbcrs within cach dimcnsion. Thcy arc
uscd to rclinc qucrics conccrning data analysis. Cells arc parts ol a multidimcnsional
cubc that arc idcntilicd by coordinatcs (x, y, and zcoordinatc, il thc cubc is thrcc
dimcnsional). This mcans that a ccll is a sct containing mcmbcrs lrom cach dimcnsion.
For instancc, considcr thc thrccdimcnsional cubc in Chaptcr 22 (scc Figurc 223) that
rcprcscnts car salcs lor a singlc rcgion within a quartcr. Thc cclls with thc lollowing
coordinatcs bclong, among othcrs, to thc cubc:
First quartcr, South Amcrica, Falcon

Vhcn you dclinc hicrarchics, you dclinc thcm in tcrms ol thcir lcvcls. !n othcr
words, le.els dcscribc thc hicrarchy lrom thc highcst (most summarizcd) lcvcl to thc
lowcst (most dctailcd) lcvcl ol data. Thc lollowing list displays thc possiblc hicrarchy
lcvcls lor thc timc dimcnsion:
Quartcr (Q1, Q2, Q3, Q4)
Month ( January, Fcbruary, .)
ay (ay1, ay2, .)
Cha pt er 2 3: Mi c r os of t Ana l ys i s S er v i c es 573
Creating a Cube
8clorc you crcatc a cubc, you must spccily onc or morc data sourccs and crcatc a data
sourcc vicw, as dcscribcd carlicr in thc chaptcr. Altcr that, you can usc thc Cubc Vizard
to crcatc a cubc.
To crcatc a cubc, rightclick thc Cubes loldcr ol thc particular projcct in thc Solution
Explorer panc and sclcct New Cube. Thc Cubc Vizard appcars. Thcn, on thc Select
Creation Method pagc, choosc Use existing tables and click Next. n thc Select
Measure Group Tables pagc, sclcct thc data sourcc vicw, click thc Suggest button, and
thcn click Next.
n thc Select Measure pagc, sclcct thc lollowing mcasurcs: SalesAmount (in thc
IactResellerSales lact tablc) and TotalProductCost (in thc IactnternetSales lact
tablc). Click Next. n thc Select New Dimensions pagc, sclcct all thrcc dimcnsions
(DimTime, DimProduct, and DimCustomer) to bc crcatcd, bascd on availablc tablcs.
Thc linal pagc, Completing the Wizard, shows thc summary ol all sclcctcd mcasurcs
and dimcnsions (scc Figurc 235). Click Iinish to linish thc work.
Designing Storage Aggregation
and Processing tbe Cube
As you alrcady know, basic data lrom thc lact tablc can bc summarizcd in advancc and
storcd in pcrsistcnt tablcs. This proccss is callcd "aggrcgation," and it can signilicantly
||qcre 11- tcm(|e||s ||e |cc/1 (ce
574 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
cnhancc thc rcsponsc timc ol qucrics, bccausc scanning millions ol rows to calculatc thc
aggrcgation on thc lly can takc a vcry long timc.
Thcrc is a tradcoll bctwccn storagc rcquircmcnts and thc pcrccntagc ol possiblc
aggrcgations that arc calculatcd and storcd. Calculating all possiblc aggrcgations in a
cubc and thcir storagc on thc disk rcsults in thc lastcst possiblc rcsponsc timc lor all
qucrics, bccausc thc rcsponsc to cach qucry is almost immcdiatc. Thc disadvantagc ol
this approach is that thc storagc and proccssing timc rcquircd lor thc aggrcgations can
bc substantial.
n thc othcr hand, il no aggrcgations arc calculatcd and storcd, you do not nccd any
additional disk storagc, but rcsponsc timc lor qucrics conccrning aggrcgatc lunctions
will bc slow, bccausc cach aggrcgatc has to bc calculatcd on thc lly.
Analysis Scrviccs providcs thc Aggrcgation csign Vizard to hclp you dcsign
aggrcgations optimally. To start thc wizard, click thc Partitions tab in thc Cube
Designer. (Figurc 236 shows thc Partitions tab lor thc IactnternetSales lact tablc.)
!n thc tablc that appcars in thc Cubc csigncr (IactnternetSales), click thc valuc
undcr thc Aggregations column. Altcr that, click . in thc samc licld. That starts thc
Aggrcgation csign Vizard.
!n thc lirst stcp ol thc wizard, you rcvicw aggrcgation usagc scttings in thc window
with thc samc namc. !n this stcp, you can includc or cxcludc thc attributcs that appcar
on thc pagc.
Thc ncxt stcp altcr sclccting thc storagc structurc is to spccily thc numbcr ol mcmbcrs
in cach attributc. You do this on thc Specify Objects Counts pagc. For cach sclcctcd
cubc objccts you must cntcr thc cstimatcd count valuc or partition count valuc, bclorc you
start thc wizard, clicking Count button to start thc wizard, which counts and displays thc
obtaincd count numbcr.
||qcre 11-6 |e |c/||||css |c| /c/ ||e |c:||s|e/se|:c|es /c:| |c||e
Cha pt er 2 3: Mi c r os of t Ana l ys i s S er v i c es 575
!n thc sccondtolast stcp, thc Set Aggregation Options pagc, shown in Figurc 237,
choosc onc ol thc lour options to spccily up to what point (or not at all) aggrcgations
should bc dcsigncd:
Estimated storage reaches__MB
thc morc prccalculatcd aggrcgations that will bc crcatcd.
Performance gain reaches__%
pcrlormancc.
click Stop nablcs you to dccidc whcn to stop thc dcsign proccss.
Do not design aggregation (0%)
should bc crcatcd.
Altcr you click thc Start button and thc Next button, thc Completing the wizard
pagc appcars. n this pagc, you can choosc whcthcr to proccss aggrcgations immcdiatcly
(Deploy and process now) or latcr (Save the aggregations but do not process them).
||qcre 11-I |e :e| //ec||cs 0(||css (ce
576 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Thc Process Progress window shows thc dcploymcnt progrcss ol proccssing thc cubc
(scc Figurc 238).
/ :a|e mas| |e (/c:esse1 a|es ,ca /|/s| :/ec|e || cs1 ec:| ||me ,ca mc1|/, ||. |/ c :a|e |cs c |c| c/ 1c|c cs1
(/e:cm(a|e1 c/ec||css, (/c:ess|s ||e :a|e :cs |e |e/, ||me :cssam|s.
rowsing a Cube
To browsc a cubc, rightclick thc cubc namc and sclcct Browse. Thc Browse vicw appcars.
You can add any ol thc dimcnsions to thc vicw by rightclicking thc dimcnsion namc in
thc lclt panc and sclccting Add to Column Area or Add to Row Area. You can also add a
mcasurc lrom thc samc panc il you rightclick thc mcasurc and sclcct Add to Data Area.
Figurc 239 shows thc salcs amounts lor !ntcrnct salcs lor dillcrcnt customcrs and dillcrcnt
products. To show thcsc amounts, rightclick thc DimProduct tablc and sclcct Add to
Column Area. Also rightclick thc DimCustomer tablc and sclcct Add to Row Area. Thc
mcasurc SalesAmount lrom thc IactnternetSales lact tablc will bc droppcd analogously.
||qcre 11-8 |e (/c:ess (/c/ess a|s1ca
Cha pt er 2 3: Mi c r os of t Ana l ys i s S er v i c es 577
ca :cs ase |c es|c/e ||e 8tewse ||ea c/ ||e ta|e |es|se/. |e scme |e,s|/c|e :cm||sc||cs
/e|e/|s |c:| |c sc/mc| ||ea.
ConcIusion
Vith its Analysis Scrviccs, Microsolt ollcrs a sct ol data warchousing scrviccs that
can bc uscd lor cntry and intcrmcdiatclcvcl data analysis. !n particular, its casc ol usc
through 8! cvclopmcnt Studio, which is bascd upon \isual Studio, will givc uscrs an
casy way to dcsign and dcvclop data warchouscs and data marts.
Thc ncxt chaptcr dcscribcs SQL/LAP cxtcnsions in TransactSQL.
||qcre 11-9 t/css|c| a||| sc|es cmcas|s /c/ |s|e/se| sc|es
This page intentionally left blank
In 7bis Cbapter
Introduction to SL/DLAP
Window Construct
xtensions of CRDUP Y
DLAP uery Functions
Nonstandard AnaIytic
Functions
Iuslncss Intclllgcncc
and Jransact-SQI
Cbapter 24
Copyright 2008 by The McGraw-Hill Companies. Click here for terms of use.
580 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
P
art !! ol this book showcd thc powcr ol thc TransactSQL languagc lor managing
traditional busincss data. Prior to SQL Scrvcr 2000, thc TransactSQL languagc
did not handlc complcx data analysis particularly wcll. From its inccption,
TransactSQL has providcd scvcral aggrcgatc lunctions that can bc uscd to computc
simplc summary data, and thc GRUP 8Y clausc, which ollcrs clcmcntary grouping
ol data.
SQL Scrvcr 2000 was thc lirst vcrsion ol SQL Scrvcr to providc complcx data
analysis lacilitics, such as thc CU8 opcrator and thc TP clausc. SQL Scrvcr
2005 cxtcndcd signilicantly thcsc lacilitics, introducing ranking lunctions and scvcral
rclational opcrators. SQL Scrvcr 2008 introduccs thc standardizcd syntax lor thc
RLLUP and CU8 opcrators, as wcll as grouping scts, which allow you to computc
groups on scvcral dillcrcnt scts ol grouping columns.
Altcr a short introduction to SQL/LAP, this chaptcr discusscs thc lollowing topics
conccrning analytic lunctions:
Vindow construct
xtcnsions ol thc GRUP 8Y clausc
Analytic qucry lunctions
Nonstandard analytic lunctions
Introduction to SL/DLAP
Havc you cvcr tricd to writc a TransactSQL qucry that computcs thc pcrccntagc
changc in valucs bctwccn last two quartcrs: r onc that implcmcnts cumulativc sums
or sliding aggrcgations: !l you havc cvcr tricd, you know how dillicult thcsc tasks arc.
Today, you don't havc to implcmcnt thcm any morc. Thc SQL:1999 standard has
adoptcd a sct ol onlinc analytical proccssing (LAP) lunctions that cnablc you to casily
pcrlorm thcsc calculations as wcll as many othcrs that uscd to bc vcry complcx lor
implcmcntation. This part ol thc SQL standard is callcd SQL/LAP. Thcrclorc, SQL/
LAP compriscs all lunctions and opcrators that arc uscd lor data analysis.
Using LAP lunctions has scvcral advantagcs lor uscrs:
Uscrs with standard knowlcdgc ol thc SQL languagc can casily spccily thc
calculations thcy nccd.
atabasc systcms, such as atabasc nginc, can pcrlorm thcsc calculations much
Cha pt er 2 4: 8us i nes s | nt el l i genc e a nd Tr a ns a c t - S QL 581

morc cconomical lor tool and application vcndors to cxploit.
Almost all thc analytic lunctions proposcd by thc SQL:1999 standard arc
implcmcntcd in cntcrprisc databasc systcms in thc samc way. For this rcason, you
can port qucrics in rclation to SQL/LAP lrom onc systcm to anothcr, without
any codc changcs.
atabasc nginc ollcrs many cxtcnsions to thc SLCT statcmcnt that can bc uscd
primarily lor analytic opcrations. Somc ol thcsc cxtcnsions arc dclincd according to thc
SQL:1999 standard and somc arc not. Thc lollowing scctions dcscribc both standard
and nonstandard SQL/LAP lunctions and opcrators.
Window Construct
Thc most important cxtcnsion ol TransactSQL conccrning data analysis is thc window
construct. A window (in rclation to SQL/LAP) dclincs a partitioncd sct ol rows to
which a lunction is applicd. Thc numbcr ol rows that bclong to a window is dynamically
dctcrmincd in rclation to thc uscr's spccilications. Thc window construct is spccilicd
using thc \R clausc.
Thc standardizcd window construct has thrcc main parts:
Partitioning
rdcring
Aggrcgation grouping
:9| :e/|e/ 1^^? 1cess| sa((c/| c/ec||cs /ca(|s, sc |||s /ec|a/e |s sc| 1|s:asse1 |e/e.

8clorc you dclvc into thc window construct and its parts, takc a look at thc tablc
that will bc uscd lor thc cxamplcs. xamplc 24.1 crcatcs thc project_dept tablc, shown
in Tablc 241, which is uscd in this chaptcr to dcmonstratc TransactSQL cxtcnsions
conccrning SQL/LAP.
582 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
XAMPL 24.1
US samplc,
crcatc tablc projcct_dcpt
( dcpt_namc char( 20 ) not null,
cmp_cnt int null,
budgct lloat,
datc_month datc ),
Thc project_dept tablc contains scvcral dcpartmcnts and thcir cmploycc counts as
wcll as budgcts ol projccts that arc controllcd by cach dcpartmcnt. xamplc 24.2 shows
thc !NSRT statcmcnts that arc uscd to inscrt thc rows shown in Tablc 241.
XAMPL 24.2
!NSRT !NT projcct_dcpt \ALUS
('Rcscarch', 5, 50000, '01.01.2007'),
!NSRT !NT projcct_dcpt \ALUS
('Rcscarch', 10, 70000, '02.01.2007'),
!NSRT !NT projcct_dcpt \ALUS
('Rcscarch', 5, 65000, '07.01.2007'),
!NSRT !NT projcct_dcpt \ALUS
('Accounting', 5, 10000, '07.01.2007'),
Iah|e 14-1 tcs|es| c/ ||e (/c(e:|_1e(| |c||e
6ept_aame emp_cat hc6qet 6ate_meath
|e.e+rc| ! ! ..zI
|e.e+rc| I z..zI
|e.e+rc| ! ! I..zI
|cceaat|a ! I..zI
|cceaat|a + z..zI
|cceaat|a 1 ..zI
|cceaat|a + z..z
M+r|et|a ..z
M+r|et|a z..z
M+r|et|a 1 I..z
M+r|et|a NJ|| z ..z
Cha pt er 2 4: 8us i nes s | nt el l i genc e a nd Tr a ns a c t - S QL 583
!NSRT !NT projcct_dcpt \ALUS
('Accounting', 10, 40000, '02.01.2007'),
!NSRT !NT projcct_dcpt \ALUS
('Accounting', 6, 30000, '01.01.2007'),
!NSRT !NT projcct_dcpt \ALUS
('Accounting', 6, 40000, '02.01.2008'),
!NSRT !NT projcct_dcpt \ALUS
('Markcting', 6, 100000, '01.01.2008'),
!NSRT !NT projcct_dcpt \ALUS
('Markcting', 10, 180000, '02.01.2008'),
!NSRT !NT projcct_dcpt \ALUS
('Markcting', 3, 100000, '07.01.2008'),
!NSRT !NT projcct_dcpt \ALUS
('Markcting', NULL, 120000, '01.01.2008'),
Partitioning
Partitioning allows you to dividc thc rcsult sct ol a qucry into groups, so that cach row
lrom a partition will bc displaycd scparatcly. !l no partitioning is spccilicd, thc cntirc
sct ol rows compriscs a singlc partition. Although thc partitioning looks likc a grouping
using thc GRUP 8Y clausc, it is not thc samc thing. Thc GRUP 8Y clausc
collapscs thc rows in a partition into a singlc row, whcrcas thc partitioning within thc
window construct simply organizcs thc rows into groups without collapsing thcm.
Thc lollowing two cxamplcs show thc dillcrcncc bctwccn partitioning using thc
window construct and grouping using thc GRUP 8Y clausc. Supposc that you want
to calculatc scvcral dillcrcnt aggrcgatcs conccrning cmployccs in cach dcpartmcnt.
xamplc 24.3 shows how thc \R clausc with thc PART!T!N 8Y clausc can bc
uscd to build partitions.
XAMPL 24.3
Using thc window construct, build thc partition according to thc valucs in thc dept_
name column and calculatc thc sum and thc avcragc lor thc Accounting and Rcscarch
dcpartmcnts:
US samplc,
SLCT dcpt_namc, budgct,
SUM( cmp_cnt ) \R( PART!T!N 8Y dcpt_namc ) AS cmp_cnt_sum,
A\G( budgct ) \R( PART!T!N 8Y dcpt_namc ) AS budgct_avg
FRM projcct_dcpt
VHR dcpt_namc !N ('Accounting', 'Rcscarch'),
584 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Thc rcsult is
6ept_aame hc6qet emp_cat_scm hc6qet_aq
|cceaat|a zI 1
|cceaat|a + zI 1
|cceaat|a 1 zI 1
|cceaat|a + zI 1
|e.e+rc| ! z .I
|e.e+rc| I z .I
|e.e+rc| ! z .I
xamplc 24.3 uscs thc \R clausc to dclinc thc corrcsponding window. !nsidc
it, thc PART!T!N 8Y option is uscd to spccily partitions. (Thc partitions arc
groupcd using thc valucs in thc dept_name column.) Finally, an aggrcgatc (or somc
othcr) lunction is applicd to thc partitions. Again, as you can scc lrom thc rcsult ol thc
cxamplc, thc partitioning organizcs thc rows into groups without collapsing thcm.
xamplc 24.4 shows a similar qucry that uscs thc GRUP 8Y clausc.
XAMPL 24.4
Group thc valucs in thc dept_name column lor thc Accounting and Rcscarch
dcpartmcnts and calculatc thc sum and thc avcragc lor thcsc two groups:
US samplc,
SLCT dcpt_namc,
SUM(cmp_cnt) AS cnt, A\G( budgct ) AS budgct_avg
FRM projcct_dcpt
VHR dcpt_namc !N ('Accounting', 'Rcscarch')
GRUP 8Y dcpt_namc,
Thc rcsult is
6ept_aame cat hc6qet_aq
|cceaat|a zI 1
|e.e+rc| z .I
As alrcady statcd, whcn you usc thc GRUP 8Y clausc, cach group collapscs in
onc row.
Cha pt er 2 4: 8us i nes s | nt el l i genc e a nd Tr a ns a c t - S QL 585
|e/e |s csc||e/ s|s|/|:cs| 1|//e/es:e |e|aees ||e 0l|| cs1 |0|| 3 :|cases. /s :cs |e sees //cm
|scm(|e 1+.1, a|es ,ca ase ||e 0l|| :|case, ||e :c//es(cs1|s :|||t ||s| :cs :cs|c|s cs, :c|ams scme
//cm ||e |c||e. ||s |s c|||cas, |e:case (c/||||cs|s c/cs|ces ||e /cas |s|c /ca(s a|||ca| :c||c(s|s ||em.
Ordering
Thc ordcring within thc window construct is likc thc ordcring in a qucry: lirst, you
usc thc RR 8Y clausc to spccily thc particular ordcr ol thc rows in thc rcsult sct.
Sccond, it includcs a list ol sort kcys and indicatcs whcthcr thcy should bc sortcd in
asccnding or dcsccnding ordcr. Thc most important dillcrcncc is that ordcring insidc a
window is applicd only .ithin cach partition.
SQL Scrvcr 2008 docsn't support ordcring insidc a window construct for aggregate
functions. !n othcr words, thc \R clausc lor aggrcgatc lunctions can contain only thc
PART!T!N 8Y clausc. (!n spitc ol this limitation, ordcring insidc a window works lor
ranking lunctions.) xamplc 24.5, which is supportcd by thc SQL standard, displays an crror.
XAMPL 24.5(DISPLAYS AN RRDR)
Using thc window construct, partition thc rows ol thc project_dept tablc using thc
valucs in thc dept_name column and sort thc rows in cach partition using thc valucs in
thc budget column:
US samplc,
SLCT dcpt_namc, budgct, cmp_cnt
SUM(budgct) \R(PART!T!N 8Y dcpt_namc RR 8Y budgct) AS
sum_dcpt
FRM projcct_dcpt,
xamplc 24.6 uscs thc convcntional TransactSQL lcaturcs to solvc thc problcm
in xamplc 24.5, which is callcd "cumulativc aggrcgations," or in this casc "cumulativc
sums." Cumulativc aggrcgations accumulatc data lrom thc lirst valuc within thc
partition up to thc currcnt valuc.
XAMPL 24.6
Group thc project_dept tablc using thc valucs in thc dept_name column and sort thc
rows in cach partition using thc valucs in thc budget column:
US samplc,
SLCT p1.dcpt_namc, p1.budgct, p1.cmp_cnt,
586 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
SUM (p2.budgct) AS cumulativc_budgct
FRM projcct_dcpt p1 J!N projcct_dcpt p2
N p1.dcpt_namc -p2.dcpt_namc
AN p2.budgct - p1.budgct
GRUP 8Y p1.dcpt_namc, p1.budgct, p1.cmp_cnt
RR 8Y p1.dcpt_namc, p1.budgct, p1.cmp_cnt,
|e :9| s|cs1c/1 1e/|ses cs c11|||csc| (c/| c/ ||e a|s1ca :css|/a:| :c||e1 c/ec||cs /ca(|s. |||
c/ec||cs /ca(|s, ,ca :cs 1e/|se c se| c/ /cas cs a||:| ||e c/ec|e /as:||cs c(e/c|es /c/ ec:| /ca |s
||e (c/||||cs. /cssc:|-:9| 1cess| sa((c/| c/ec||cs /ca(|s.
You can usc scvcral columns lrom a tablc to build dillcrcnt partitioning schcmas in a
qucry, as shown in xamplc 24.7.
XAMPL 24.7
Using thc window construct, build two partitions lor thc Accounting and Rcscarch
dcpartmcnts: onc using thc valucs ol thc budget column and thc othcr using thc valucs
ol thc dept_name column. Calculatc thc sums lor thc lormcr partition and thc avcragcs
lor thc lattcr partition.
US samplc,
SLCT dcpt_namc, CAST( budgct AS !NT ) AS budgct,
SUM( cmp_cnt ) \R( PART!T!N 8Y budgct ) AS cmp_cnt_sum,
A\G( budgct ) \R( PART!T!N 8Y dcpt_namc ) AS budgct_avg
FRM projcct_dcpt
VHR dcpt_namc !N ('Accounting', 'Rcscarch'),
Thc rcsult is
6ept_aame hc6qet emp_cat_scm hc6qet_aq
|cceaat|a ! 1
|cceaat|a 1 1
|cceaat|a + 1
|cceaat|a + 1
|e.e+rc| ! ! .I
|e.e+rc| ! ! .I
|e.e+rc| I .I
Cha pt er 2 4: 8us i nes s | nt el l i genc e a nd Tr a ns a c t - S QL 587
Thc qucry in xamplc 24.7 has two dillcrcnt partitioning schcmas: onc ovcr thc
valucs ol thc budget column and onc ovcr thc valucs ol thc dept_name column. Thc
lormcr is uscd to calculatc thc numbcr ol cmployccs in rclation to thc dcpartmcnts
with thc samc budgct. Thc lattcr is uscd to calculatc thc avcragc valuc ol budgcts ol
dcpartmcnts groupcd by thcir namcs.
xtensions of CRDUP Y
TransactSQL cxtcnds thc GRUP 8Y clausc with thc lollowing opcrators:
CU8
RLLUP
GRUP!NG STS
Thc GRUP 8Y clausc has also an additional GRUP!NG lunction, which will bc
discusscd altcr thc opcrators mcntioncd abovc.
CU Dperator
This scction looks at thc dillcrcnccs bctwccn grouping using thc GRUP 8Y clausc
alonc and grouping using GRUP 8Y in combination with thc CU8 opcrator. Thc
main dillcrcncc is that thc GRUP 8Y clausc dclincs onc or morc columns as a group
such that all rows within any group havc thc samc valucs lor thosc columns. CU8 and
RLLUP providc additional summary rows lor groupcd data. Thcsc summary rows arc
also callcd multidimcnsional summarics.
Thc lollowing two cxamplcs dcmonstratc thcsc dillcrcnccs. xamplc 24.8 applics
thc GRUP 8Y clausc to group thc rows ol thc project_dept tablc using two critcria:
dept_name and emp_cnt.
XAMPL 24.8
Using GRUP 8Y, group thc rows ol thc project_dept tablc using thc dept_name
and emp_cnt columns:
US samplc,
SLCT dcpt_namc, cmp_cnt, SUM(budgct) sum_ol_budgcts
FRM projcct_dcpt
VHR dcpt_namc !N ('Accounting', 'Rcscarch')
GRUP 8Y dcpt_namc, cmp_cnt,
588 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Thc rcsult is
6ept_aame emp_cat scm_ef_hc6qets
|cceaat|a !
|e.e+rc| ! !
|cceaat|a I
|cceaat|a +
|e.e+rc| I
xamplc 24.9 and its rcsult sct shows thc dillcrcncc whcn you additionally usc thc
CU8 opcrator.
XAMPL 24.9
Group thc rows ol thc project_dept tablc that bclong to thc Accounting and Rcscarch
dcpartmcnts using thc dept_name and emp_cnt columns and additionally display all
possiblc summary rows:
US samplc,
SLCT dcpt_namc, cmp_cnt, SUM(budgct) sum_ol_budgcts
FRM projcct_dcpt
VHR dcpt_namc !N ('Accounting', 'Rcscarch')
GRUP 8Y CU8 (dcpt_namc, cmp_cnt),
Thc rcsult is
6ept_aame emp_cat scm_ef_hc6qets
|cceaat|a !
|cceaat|a I
|cceaat|a +
|cceaat|a NJ|| z
|e.e+rc| ! !
|e.e+rc| I
|e.e+rc| NJ|| !
NJ|| NJ|| 1!
NJ|| ! z!
NJ|| I
NJ||
Cha pt er 2 4: 8us i nes s | nt el l i genc e a nd Tr a ns a c t - S QL 589
Thc main dillcrcncc bctwccn thc last two cxamplcs is that thc rcsult sct ol
xamplc 24.8 displays only thc valucs in rclation to thc grouping, whilc thc rcsult sct
ol xamplc 24.9 contains, additionally, all possiblc summary rows. Thc placcholdcr
lor thc valucs in thc unnccdcd columns ol summary rows is displaycd as NULL. For
cxamplc, thc lollowing row lrom thc rcsult sct
NULL NULL 305000
shows thc sum ol all budgcts ol all cxisting projccts in thc tablc, whilc thc row
NULL 5 125000
shows thc sum ol all budgcts lor all projccts that cmploy cxactly livc cmployccs.
3e:case ||e t|3| c(e/c|c/ 1|s(|c,s e|e/, (css|||e :cm||sc||cs c/ /ca(s cs1 sammc/, /cas, ||e sam|e/ c/
/cas |s ||e scme, /ec/1|ess c/ ||e c/1e/ c/ :c|amss |s ||e |0|| 3 :|case.
Thc syntax ol CU8 in xamplc 24.9 corrcsponds to thc standardizcd syntax
ol that opcrator. This syntax is introduccd in SQL Scrvcr 2008. xamplc 24.10 is
cquivalcnt to xamplc 24.9 but uscs thc oldstylc syntax.
XAMPL 24.10
Group thc rows ol thc project_dept tablc that bclong to thc Accounting and Rcscarch
dcpartmcnts using thc dept_name and emp_cnt columns and additionally display all
possiblc summary rows:
US samplc,
SLCT dcpt_namc, cmp_cnt, SUM(budgct) sum_ol_budgcts
FRM projcct_dcpt
VHR dcpt_namc !N ('Accounting', 'Rcscarch')
GRUP 8Y dcpt_namc, cmp_cnt
V!TH CU8,
RDLLUP Dperator
!n contrast to CU8, which rcturns cvcry possiblc combination ol groups and
summary rows, thc group hicrarchy using RLLUP is dctcrmincd by thc ordcr
in which thc grouping columns arc spccilicd. xamplc 24.11 shows thc usc ol thc
RLLUP opcrator.
590 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
XAMPL 24.11
Group thc rows ol thc project_dept tablc that bclong to thc Accounting and Rcscarch
dcpartmcnts using thc dept_name and emp_cnt columns and additionally display
summary rows lor thc dept_name column:
US samplc,
SLCT dcpt_namc, cmp_cnt, SUM(budgct) sum_ol_budgcts
FRM projcct_dcpt
VHR dcpt_namc !N ('Accounting', 'Rcscarch')
GRUP 8Y RLLUP (dcpt_namc, cmp_cnt),
Thc rcsult is
6ept_aame emp_cat scm_ef_hc6qets
|cceaat|a !
|cceaat|a I
|cceaat|a +
|cceaat|a NJ|| z
|e.e+rc| ! !
|e.e+rc| I
|e.e+rc| NJ|| !
NJ|| NJ|| 1!
As you can scc lrom thc rcsult ol xamplc 24.11, thc numbcr ol rctricvcd rows in
this cxamplc is smallcr than thc numbcr ol displaycd rows in thc cxamplc with thc
CU8 opcrator. Thc rcason is that thc summary rows arc displaycd only lor thc lirst
column in thc GRUP 8Y clausc.
|e s,s|cs ase1 |s |scm(|e 1+.!! |s ||e s|cs1c/1|ce1 s,s|cs ||c| acs |s|/c1a:e1 |s :9| :e/|e/ 1^^?. |e
c|1-s|,|e s,s|cs /c/ |0|||| |s s|m||c/ |c ||e s,s|cs /c/ t|3|, a||:| |s s|cas |s |scm(|e 1+.!^.
CRDUPINC Function
As you alrcady know, NULL is uscd in combination with CU8 and RLLUP to
spccily thc placcholdcr lor thc valucs in thc unnccdcd columns. !n such a casc, it isn't
possiblc to distinguish NULL in rclation to CU8 and RLLUP lrom thc NULL
valuc. TransactSQL supports thc standardizcd GRUP!NG lunction, which allows
Cha pt er 2 4: 8us i nes s | nt el l i genc e a nd Tr a ns a c t - S QL 591
you to rcsolvc thc problcm with thc ambiguity ol NULL. Thc GRUP!NG lunction
rcturns 1 il thc NULL in thc rcsult sct is in rclation to CU8 or RLLUP, and 0 il it
rcprcscnts thc group ol NULL valucs.
xamplc 24.12 shows thc usc ol thc GRUP!NG lunction.
XAMPL 24.12
Using thc GRUP!NG lunction, clarily which NULL valucs in thc rcsult ol thc
lollowing SLCT statcmcnt display summary rows:
US samplc,
SLCT dcpt_namc, cmp_cnt, SUM(budgct) sum_b, GRUP!NG(cmp_cnt) gr
FRM projcct_dcpt
VHR dcpt_namc !N ('Accounting', 'Markcting')
GRUP 8Y RLLUP (dcpt_namc, cmp_cnt),
Thc rcsult is
6ept_aame emp_cat scm_h qr
|cceaat|a !
|cceaat|a I
|cceaat|a +
|cceaat|a NJ|| z
M+r|et|a NJ|| z
M+r|et|a 1
M+r|et|a
M+r|et|a
M+r|et|a NJ|| !
NJ|| NJ|| z
!l you takc a look at thc grouping column (gr), you will scc that somc valucs arc 0
and somc arc 1. Thc valuc 1 indicatcs that thc corrcsponding NULL in thc emp_cnt
column spccilics a summary valuc.
Crouping S7S Dperator
Grouping scts arc an cxtcnsion to thc GRUP 8Y clausc that lcts uscrs dclinc scvcral
groups in thc samc qucry. You usc thc GRUP!NG STS opcrator to implcmcnt
grouping scts. xamplc 24.13 shows thc usc ol this opcrator.
592 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
XAMPL 24.13
Calculatc thc sum ol budgcts lor thc Accounting and Rcscarch dcpartmcnts using thc
combination ol valucs ol thc dept_name and emp_cnt columns lirst, and altcr that
using thc valucs ol thc singlc column dept_name:
US samplc,
SLCT dcpt_namc, cmp_cnt, SUM(budgct) sum_budgcts
FRM projcct_dcpt
VHR dcpt_namc !N ('Accounting', 'Rcscarch')
GRUP 8Y GRUP!NG STS ((dcpt_namc, cmp_cnt),(dcpt_namc)),
Thc rcsult is
6ept_aame emp_cat scm_hc6qets
|cceaat|a !
|cceaat|a I
|cceaat|a +
|cceaat|a NJ|| z
|e.e+rc| ! !
|e.e+rc| I
|e.e+rc| NJ|| !
As you can scc lrom thc rcsult sct ol xamplc 24.13, thc qucry uscs two dillcrcnt
groupings to calculatc thc sum ol budgcts: lirst using thc combination ol valucs ol thc
dept_name and emp_cnt columns, and sccond using thc valucs ol thc singlc column
dept_name.
You can usc thc scrics ol grouping scts to rcplacc thc RLLUP and CU8 opcrators.
For instancc, thc lollowing scrics ol grouping scts
GRUP 8Y GRUP!NG STS ((dcpt_namc, cmp_cnt), (dcpt_namc), ())
is cquivalcnt to thc lollowing RLLUP clausc:
GRUP 8Y RLLUP (dcpt_namc, cmp_cnt)
Also,
GRUP 8Y GRUP!NG STS ((dcpt_namc, cmp_cnt), (cmp_cnt, dcpt_namc),
(dcpt_namc), ())
Cha pt er 2 4: 8us i nes s | nt el l i genc e a nd Tr a ns a c t - S QL 593
is cquivalcnt to thc lollowing CU8 clausc:
GRUP 8Y CU8 (dcpt_namc, cmp_cnt)
DLAP uery Functions
TransactSQL supports two groups ol lunctions that arc catcgorizcd as LAP qucry
lunctions:
Ranking lunctions
Statistical aggrcgatc lunctions
Thc lollowing subscctions dcscribc thcsc lunctions.
|e |0|||| /as:||cs, 1|s:asse1 (/e||cas|,, c|sc |e|css |c ||e 0|/| /as:||css.

Ranking Functions
Ranking lunctions rcturn a ranking valuc lor cach row in a partition group. Transact
SQL supports thc lollowing ranking lunctions:
RANK
NS_RANK
RV_CUNT
xamplc 24.14 shows thc usc ol thc RANK lunction.
XAMPL 24.14
Find all dcpartmcnts with a budgct not grcatcr than 30000, and display thc rcsult sct in
dcsccnding ordcr:
US samplc,
SLCT RANK() \R(RR 8Y budgct SC) AS rank_budgct,
dcpt_namc, cmp_cnt, budgct
FRM projcct_dcpt
VHR budgct - 30000,
594 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Thc rcsult is
raak_hc6qet 6ept_aame emp_cat hc6qet
|cceaat|a 1
z |cceaat|a !
xamplc 24.14 uscs thc RANK lunction to rcturn a numbcr (in thc lirst column ol
thc rcsult sct) that spccilics thc rank ol thc row among all rows. Thc cxamplc uscs thc
\R clausc to sort thc rcsult sct by thc budget column in thc dcsccnding ordcr. (!n
this cxamplc, thc PART!T!N 8Y clausc is omittcd. For this rcason, thc wholc rcsult
sct will bclong to only onc partition.)
|e |/|| /as:||cs ases |c|:c| c/ec||cs. |s c||e/ ac/1s, |/ |ac c/ mc/e /cas |s c /esa|| se| c/e ||e1
(|c|e c scme |c|ae |s ||e c/1e/|s :c|ams, ||e, a||| |c|e ||e scme /cs|. |e /ca a||| ||e sa|seaes|
c/1e/|s a||| |c|e c /cs| ||c| |s cse (|as ||e sam|e/ c/ /cs|s ||c| (/e:e1e ||e /ca. |c/ |||s /ecscs, ||e |/||
/as:||cs 1|s(|c,s c(s |/ |ac c/ mc/e /cas |c|e ||e scme /cs||s.
xamplc 24.15 shows thc usc ol thc two othcr ranking lunctions, NS_RANK
and RV_NUM8R.
XAMPL 24.15
Find all dcpartmcnts with a budgct not grcatcr than 40000, and display thc dcnsc rank
and thc scqucntial numbcr ol cach row in thc rcsult sct:
US samplc,
SLCT NS_RANK() \R( RR 8Y budgct SC ) AS rank_budgct,
RV_NUM8R() \R( RR 8Y budgct SC ) AS row_numbcr,
dcpt_namc, cmp_cnt, budgct
FRM projcct_dcpt
VHR budgct - 40000,
Thc rcsult is
raak_hc6qet rew_acmher 6ept_aame emp_cat hc6qet
|cceaat|a +
z |cceaat|a +
z 1 |cceaat|a 1
1 + |cceaat|a !
Cha pt er 2 4: 8us i nes s | nt el l i genc e a nd Tr a ns a c t - S QL 595
Thc lirst two columns in thc rcsult sct ol xamplc 24.15 show thc valucs lor
thc NS_RANK and RV_NUM8R lunctions, rcspcctivcly. Thc output ol
thc NS_RANK lunction is similar to thc output ol thc RANK lunction (scc
xamplc 24.14). Thc only dillcrcncc is that thc NS_RANK lunction rcturns no
"gaps" il two or morc ranking valucs arc cqual and thus bclong to thc samc ranking.
Thc usc ol thc RV_NUM8R lunction is obvious: it rcturns thc scqucntial
numbcr ol a row within a rcsult sct, starting at 1 lor thc lirst row.
!n thc last two cxamplcs, thc \R clausc is uscd to dctcrminc thc ordcring ol
thc rcsult sct. As you alrcady know, this clausc can bc also uscd to dividc thc rcsult sct
produccd by thc FRM clausc into groups (partitions), and thcn to apply an aggrcgatc
or ranking lunction to cach partition scparatcly.
xamplc 24.16 shows how thc RANK lunction can bc applicd to partitions.
XAMPL 24.16
Using thc window construct, partition thc rows ol thc project_dept tablc according to
thc valucs in thc date_month column. Sort thc rows in cach partition and display thcm
in asccnding ordcr.
US samplc,
SLCT datc_month, dcpt_namc, cmp_cnt, budgct,
RANK() \R( PART!T!N 8Y datc_month RR 8Y cmp_cnt dcsc ) AS
rank
FRM projcct_dcpt,
Thc rcsult is
6ate_meath 6ept_aame emp_cat hc6qet raak
zI-- |cceaat|a 1
zI-- |e.e+rc| ! ! z
zI-z- |e.e+rc| I
zI-z- |cceaat|a +
zI-I- |e.e+rc| ! !
zI-I- |cceaat|a !
z-- M+r|et|a
z-- M+r|et|a NJ|| z z
z-z- M+r|et|a
z-z- |cceaat|a + z
z-I- M+r|et|a 1
596 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Thc rcsult sct ol xamplc 24.16 is dividcd (partitioncd) into cight groups according
to thc valucs in thc date_month column. Altcr that thc RANK lunction is applicd
to cach partition. !l you takc a closcr look and comparc thc prcvious cxamplc with
xamplc 24.5, you will scc that thc last cxamplc works, whilc xamplc 24.5 displays
an crror, although both cxamplcs usc thc samc window construct. As prcviously statcd,
TransactSQL currcntly supports thc \R clausc lor aggrcgatc lunctions only with
thc PART!T!N 8Y clausc, but in thc casc ol ranking lunctions, thc systcm supports
gcncral SQL standard syntax with thc PART!T!N 8Y and RR 8Y clauscs.
StatisticaI Aggregate Functions
Chaptcr 6 introduccd statistical aggrcgatc lunctions. Thcrc arc lour ol thcm:
VAR Computcs thc variancc ol all thc valucs listcd in a column or cxprcssion.
VARP Computcs thc variancc lor thc population ol all thc valucs listcd in a
column or cxprcssion.
STDEV Computcs thc standard dcviation ol all thc valucs listcd in a column
corrcsponding variancc.)
STDEVP Computcs thc standard dcviation lor thc population ol all thc valucs
listcd in a column or cxprcssion.
You can usc statistical aggrcgatc lunctions with or without or with thc window
construct. xamplc 24.17 shows how thc lunctions \AR and ST\ can bc uscd in
rclation to thc window construct.
XAMPL 24.17
Using thc window construct, calculatc thc variancc and standard dcviation ol budgcts in
rclation to partitions lormcd using thc valucs ol thc dept_name column:
US samplc,
SLCT dcpt_namc, budgct,
\AR(budgct) \R(PART!T!N 8Y dcpt_namc) AS budgct_var,
ST\(budgct) \R(PART!T!N 8Y dcpt_namc) AS budgct_stdcv
FRM projcct_dcpt
VHR dcpt_namc in ('Accounting', 'Rcscarch'),
Cha pt er 2 4: 8us i nes s | nt el l i genc e a nd Tr a ns a c t - S QL 597
Thc rcsult is
6ept_aame hc6qet hc6qet_ar hc6qet_st6e
|cceaat|a z ++z.1!z1I1
|cceaat|a + z ++z.1!z1I1
|cceaat|a 1 z ++z.1!z1I1
|cceaat|a + z ++z.1!z1I1
|e.e+rc| ! 111111,111111 +.1zI11
|e.e+rc| I 111111,111111 +.1zI11
|e.e+rc| ! 111111,111111 +.1zI11
xamplc 24.17 uscs thc statistical aggrcgatc lunctions \AR and ST\ to calculatc
thc variancc and standard dcviation ol budgcts in rclation to partitions lormcd using
thc valucs ol thc dept_name column.
Nonstandard AnaIytic Functions
SQL Scrvcr contains scvcral LAP lunctions that arc not spccilicd in thc SQL
standard. Thc lollowing lunctions and opcrators bclong to nonstandard SQL/LAP:
TP
NT!L
P!\T and UNP!\T
Thc lollowing scctions dcscribc thcsc analytic lunctions and opcrators.
7DP CIause
Thc TP clausc spccilics thc lirst n rows ol thc qucry rcsult that arc to bc rctricvcd.
This clausc should always bc uscd with thc RR 8Y clausc, bccausc thc rcsult
ol such a qucry is always wcll dclincd and can bc uscd in tablc cxprcssions. (A tablc
cxprcssion spccilics a samplc ol a groupcd rcsult tablc.) A qucry with TP but without
thc RR 8Y clausc is nondctcrministic, mcaning that multiplc cxccutions ol thc
qucry with thc samc data must not always display thc samc rcsult sct.
xamplc 24.18 shows thc usc ol this clausc.
598 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
XAMPL 24.18
Rctricvc thc lour projccts with thc highcst budgcts:
US samplc
SLCT TP (4) dcpt_namc, budgct
FRM projcct_dcpt
RR 8Y budgct SC,
Thc rcsult is
6ept_aame hc6qet
M+r|et|a
M+r|et|a z
M+r|et|a
M+r|et|a
As you can scc lrom xamplc 24.18, thc TP clausc is part ol thc SLCT list and
is writtcn in lront ol all column namcs in thc list.
3e|ss|s a||| :9| :e/|e/ 1^^:, ,ca s|ca|1 a/||e ||e |s(a| |c|ae c/ 0| |ss|1e (c/es||eses, |e:case ||e s,s|em
sa((c/|s cs, se|/-:cs|c|se1 es(/ess|cs cs |s(a|.
Thc TP clausc is thc nonstandard TransactSQL implcmcntation uscd to display
thc ranking ol thc top n rows lrom a tablc. Thc cquivalcnt qucry to xamplc 24.18,
which uscs thc window construct and thc RANK lunction, is shown in xamplc 24.19.
XAMPL 24.19
Rctricvc thc lour projccts with thc highcst budgcts:
US samplc,
SLCT dcpt_namc, budgct
FRM (SLCT dcpt_namc, budgct,
RANK() \R (RR 8Y budgct SC) AS rank_budgct
FRM projcct_dcpt) part_dcpt
VHR rank_budgct - 4,
Thc TP clausc can also bc uscd with thc additional PRCNT option. !n that
casc, thc lirst n pcrccnt ol rows arc rctricvcd lrom thc rcsult sct. Thc additional option
Cha pt er 2 4: 8us i nes s | nt el l i genc e a nd Tr a ns a c t - S QL 599
V!TH T!S spccilics that additional rows will bc rctricvcd lrom thc qucry rcsult il
thcy havc thc samc valuc in thc RR 8Y column(s) as thc last row that bclongs to
thc displaycd sct. xamplc 24.20 shows thc usc ol thc PRCNT and V!TH T!S
options.
XAMPL 24.20
Rctricvc thc top 25 pcrccnt ol rows with thc smallcst numbcr ol cmployccs:
US samplc,
SLCT TP (25) PRCNT V!TH T!S cmp_cnt, budgct
FRM projcct_dcpt
RR 8Y cmp_cnt ASC,
Thc rcsult is
emp_cat hc6qet
NJ|| z
1
! !
! !
!
Thc rcsult ol xamplc 24.20 contains livc rows, bccausc thcrc arc thrcc projccts with
livc cmployccs.
8cginning with SQL Scrvcr 2005, you can usc thc TP clausc with UPAT,
LT, and !NSRT statcmcnts. xamplc 24.21 shows thc usc ol this clausc with
thc UPAT statcmcnt.
XAMPL 24.21
Find thc thrcc projccts with thc highcst budgct amounts and rcducc thcm by 10 pcrccnt:
US samplc
UPAT TP (3) projcct_dcpt
ST budgct - budgct 0.9
VHR budgct in (SLCT TP (3) budgct
FRM projcct_dcpt
RR 8Y budgct dcsc),
xamplc 24.22 shows thc usc ol thc TP clausc with thc LT statcmcnt.
600 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
XAMPL 24.22
clctc thc lour projccts with thc smallcst budgct amounts:
US samplc
LT TP (4)
FRM projcct_dcpt
VHR budgct !N
(SLCT TP (4) budgct FRM projcct_dcpt
RR 8Y budgct ASC),
!n xamplc 24.22, thc TP clausc is uscd lirst in thc subqucry, to lind thc lour
projccts with thc smallcst budgct amounts, and thcn in thc LT statcmcnt, to
dclctc thcsc projccts.
N7IL Function
Thc NT!L lunction bclongs to thc ranking lunctions. !t distributcs thc rows in a
partition into a spccilicd numbcr ol groups. For cach row, thc NT!L lunction rcturns
thc numbcr ol thc group to which thc row bclongs. For this rcason, this lunction is
usually uscd to arrangc rows into groups.
xamplc 24.23 shows thc usc ol thc NT!L lunction.
XAMPL 24.23
US samplc
SLCT dcpt_namc, budgct,
CAS NT!L(3) \R (RR 8Y budgct ASC)
VHN 1 THN 'Low'
VHN 2 THN 'Mcdium'
VHN 3 THN 'High'
N AS groups
FRM projcct_dcpt,
Thc rcsult is
6ept_aame hc6qet qrecps
|cceaat|a |ew
|cceaat|a 1 |ew
|cceaat|a + |ew
|cceaat|a + |ew
|e.e+rc| ! Mea|am
Cha pt er 2 4: 8us i nes s | nt el l i genc e a nd Tr a ns a c t - S QL 601
6ept_aame hc6qet qrecps
|e.e+rc| ! Mea|am
|e.e+rc| I Mea|am
M+r|et|a Mea|am
M+r|et|a |||
M+r|et|a z |||
M+r|et|a |||
PIVD7 and UNPIVD7 Dperators
P!\T and UNP!\T arc nonstandard rclational opcrators that arc supportcd by
TransactSQL. You can usc thcm to manipulatc a tablcvalucd cxprcssion into anothcr
tablc. P!\T translorms such an cxprcssion by turning thc uniquc valucs lrom
onc column in thc cxprcssion into multiplc columns in thc output, and it pcrlorms
aggrcgations on any rcmaining column valucs that arc dcsircd in thc linal output.
xamplc 24.24 shows how P!\T works.
XAMPL 24.24
US samplc,
SLCT , month(datc_month) as month, ycar(datc_month) as ycar
!NT projcct_dcpt_pivot
FRM projcct_dcpt,
G
SLCT ycar, |1| as January, |2| as Fcbruary, |7| July FRM
(SLCT budgct, ycar, month lrom projcct_dcpt_pivot) p2
P!\T (SUM(budgct) FR month !N (|1|,|2|,|7|)) AS P,
Thc rcsult is
\ear Iaacar |ehrcar Ic|
zI I!
z zz z
Thc lirst part ol xamplc 24.24 crcatcs a ncw tablc, project_dept_pivot, which will
bc uscd to dcmonstratc how thc P!\T opcrator works. This tablc is idcntical to thc
tablc project_dept (introduccd in xamplc 24.1), cxccpt lor thc two additional columns:
month and year. Thc year column ol thc project_dept_pivot tablc contains thc ycars
2007 and 2008, which appcar in thc date_month column ol thc project_dept tablc. Also,
thc month columns ol thc project_dept_pivot tablc (january, february, and july) contain
thc summarics ol budgcts corrcsponding to thcsc months in thc project_dept tablc.
602 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Thc sccond SLCT statcmcnt contains an inncr qucry, which is cmbcddcd in
thc FRM clausc ol thc outcr qucry. Thc P!\T clausc is part ol thc inncr qucry. !t
starts with thc spccilication ol thc aggrcgation lunction: SUM (ol budgcts). Thc sccond
part spccilics thc pivot column (month) and thc valucs lrom that column to bc uscd as
column hcadings (in xamplc 24.24, thc lirst, sccond, and scvcnth months ol thc ycar).
Thc valuc lor a particular column in a row is calculatcd using thc spccilicd aggrcgatc
lunction ovcr thc rows that match thc column hcading.
/s ,ca :cs see //cm |scm(|e 1+.1+, as|s c|| (css|||e |c|aes c/ ||e (||c| :c|ams |s sc| /ea|/e1.

Thc UNP!\T opcrator pcrlorms thc rcvcrsc opcration ol P!\T, by rotating
columns into rows. xamplc 24.25 shows thc usc ol this opcrator.
XAMPL 24.25
CRAT TA8L projcct_dcpt_pvt (ycar int, January lloat, Fcbruary lloat, July lloat),
!NSRT !NT projcct_dcpt_pvt \ALUS (2007, 80000, 110000, 75000),
!NSRT !NT projcct_dcpt_pvt \ALUS (2008, 50000, 80000, 30000),
UNP!\T thc tablc
SLCT ycar, month, budgct
FRM
(SLCT ycar, January, Fcbruary, July
FRM projcct_dcpt_pvt) p
UNP!\T (budgct FR month !N (January, Fcbruary, July)
)AS unpvt
Thc rcsult is
ear meath hc6qet
zI I+aa+r
zI |e|ra+r
zI Ia| I!
z I+aa+r !
z |e|ra+r
z Ia| 1
xamplc 24.25 uscs thc project_dept_pvt tablc to dcmonstratc thc UNP!\T
rclational opcrator. UNP!\T's lirst input is thc column namc (budget), which holds
thc normalizcd valucs. Altcr that, thc FR option is uscd to dctcrminc thc targct
Cha pt er 2 4: 8us i nes s | nt el l i genc e a nd Tr a ns a c t - S QL 603
column namc (month). Finally, as part ol thc !N option, thc sclcctcd valucs ol thc
targct column namc arc spccilicd.
||||l0 |s sc| ||e esc:| /e|e/se c/ ||l0, |e:case cs, |||| |c|aes |s ||e |c||e |e|s |/css/c/me1 :cssc| |e
ase1 cs :c|ams |c|aes |s ||e ca|(a|.
ConcIusion
SQL/LAP cxtcnsions in TransactSQL support data analysis lacilitics. Thcrc arc lour
main parts ol SQL/LAP that arc supportcd by SQL Scrvcr 2008:
Vindow construct
xtcnsions ol thc GRUP 8Y clausc
LAP qucry lunctions
Nonstandard analytic lunctions
Thc window construct is thc most important cxtcnsion. !n combination with ranking
and aggrcgatc lunctions, it allows you to casily calculatc analytic lunctions, such as
cumulativc and sliding aggrcgatcs, as wcll as rankings. Thcrc arc thrcc cxtcnsions to
thc GRUP 8Y clausc that arc dcscribcd in thc SQL standard and supportcd by SQL
Scrvcr 2008: thc CU8, RLLUP and GRUP!NG STS opcrators.
Thc most important analytic qucry lunctions arc ranking lunctions: RANK,
NS_RANK, and RV_NUM8R. TransactSQL supports scvcral nonstandard
analytic lunctions and opcrators, such as TP, NT!L, P!\T, and UNP!\T.
Thc ncxt chaptcr dcscribcs Rcporting Scrviccs, a busincss intclligcncc componcnt ol
SQL Scrvcr.
xercises
.24.1
Find thc avcragc numbcr ol thc cmployccs in thc Accounting dcpartmcnt. Solvc this
problcm:
a. using thc window construct
b. using thc GRUP 8Y clausc
604 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
.24.2
Using thc window construct, lind thc dcpartmcnt with thc highcst budgct lor thc ycars
2007 and 2008.
.24.3
Find thc sum ol cmployccs according to thc combination ol valucs in thc dcpartmcnts
and budgct amounts. All possiblc summary rows should bc displaycd, too.
.24.4
Solvc .24.3 using thc RLLUP opcrator. Vhat is thc dillcrcncc bctwccn this rcsult
sct and thc rcsult sct ol .24.3:
.24.5
Using thc RANK lunction, lind thc thrcc dcpartmcnts with thc highcst numbcr ol
cmployccs.
.24.6
Solvc .24.5 using thc TP clausc.
.24.7
Calculatc thc ranking ol all dcpartmcnts lor thc ycar 2008 according to thc numbcr
ol cmployccs. isplay thc valucs lor thc NS_RANK and RV_NUM8R
lunctions, too.
In 7bis Cbapter
Introduction to Microsoft
Reporting Services
Creating Reports
Processing and
Managing Reports
Accessing and
DeIivering Reports
Mlcrosolt Icportlng
Scrvlccs
Cbapter 25
Copyright 2008 by The McGraw-Hill Companies. Click here for terms of use.
606 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
T
his chaptcr dcscribcs thc SQL Scrvcr cntcrprisc rcporting tool callcd Rcport
ing Scrviccs. Thc lirst part ol thc chaptcr discusscs thc gcncral structurc ol a
rcport and cxplains thc main componcnts ol Rcporting Scrviccs. Altcr that,
you'll scc how you can crcatc rcports by using thc Rcport Scrvcr Projcct Vizard. Thc
proccssing ol a rcport is thcn cxplaincd. Finally, dillcrcnt ways to dclivcr a dcsigncd and
dcploycd rcport arc shown.
Introduction to Microsoft Reporting Services
8clorc you lcarn about thc componcnts ol Rcporting Scrviccs, you should undcrstand
thc structurc ol rcports. ach rcport has thc lollowing two instruction scts, which
togcthcr spccily thc contcnt ol thc rcport:
dataset is thc inlormation
csigncr, a tool that builds a qucry uscd in your rcport to sclcct data.
Report layout nablcs you to prcscnt sclcctcd data to thc uscr. You can spccily
hcadings and pagc numbcrs.
Vhcn thc inlormation conccrning data dclinition and rcport layout is gathcrcd,
Rcporting Scrviccs storcs it using thc Rcport clinition Languagc (RL). RL is
an XMLbascd languagc that is uscd cxclusivcly lor storing rcport dclinitions. RL
is an opcn schcma languagc, mcaning that dcvclopcrs can cxtcnd thc languagc with
additional attributcs and clcmcnts.
Rcporting Scrviccs includcs thrcc main componcnts, which rcprcscnt an application
laycr, a scrvcr laycr, and a mctadata laycr, rcspcctivcly:
Rcport Managcr
Rcport Scrvcr
Rcport Catalog
Thc lollowing scctions dcscribc thcsc componcnts.
Report Manager
Rcport Managcr is a wcbbascd rcport acccss and managcmcnt tool that runs using
!ntcrnct xplorcr. You can usc this tool to crcatc, sccurc, and maintain thc hicrarchy
Cha pt er 2 5: Mi c r os of t Pepor t i ng S er v i c es 607
ol itcms ol a singlc rcport scrvcr instancc. As a rcport scrvcr administrator, you usc
Rcport Managcr to conligurc sitc propcrtics and dclaults and to crcatc sharcd schcdulcs
and sharcd data sourccs, which makcs schcdulcs and data sourcc conncctions morc
managcablc. You can also usc Rcport Managcr to conligurc rolcbascd sccurity.
Report Server
Rcport Scrvcr is thc main componcnt ol Rcporting Scrviccs. !t is implcmcntcd as a wcb
scrvicc as wcll as a Vindows scrvicc. Thc wcb scrvicc compriscs a sct ol intcrlaccs that
clicnt applications can usc to acccss rcports ovcr a wcb scrvcr. Thc Vindows scrvicc
providcs schcduling and dclivcry scrviccs. 8oth scrviccs work togcthcr and constitutc a
singlc rcport scrvcr instancc.
As you can scc lrom Figurc 251, Rcport Scrvcr includcs scvcral componcnts:
Rcport proccssor
ata providcrs
Rcndcrcrs
Rcqucst handlcr
Thc rcport proccssor managcs thc cxccution ol a rcport. !t rctricvcs thc dclinition ol
thc rcport, which is donc in RL, and dctcrmincs what is nccdcd lor thc rcport. Also,
thc rcport proccssor managcs thc work ol othcr componcnts that arc uscd to producc a
rcport.
||qcre 1-1 tcm(cses|s c/ |e(c/| :e/|e/
Output
Report
catalog
Report server
Request
handler
Data
sources
Data
providers
Renderers
Report processor
608 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Thc rcport proccssor also rctricvcs thc data that is uscd to load thc datasct. Altcr
that, it sclccts a data providcr that knows how to gct inlormation out ol thc data sourcc.
Thc task ol thc data providcr is to conncct to thc data sourcc, gct thc inlormation lor
thc rcport, and rcturn it to thc proccssor.
Vhcn data providcrs dclivcr thc data lor thc rcport, thc rcport proccssor can bcgin
to proccss thc rcport's layout. To gcncratc thc layout, thc proccssor has to know thc
lormat ol thc rcport (HTML or PF, lor instancc). Thc rcndcrcrs arc uscd to build thc
corrcsponding lormat.
Thc rcqucst handlcr rcccivcs rcqucsts lor rcports and scnds thcm to thc rcport
proccssor. !t also dclivcrs thc complctcd rcport. (Thc dillcrcnt lorms ol rcport dclivcry
will bc discusscd latcr in thc chaptcr.)
Report CataIog
Rcport Catalog contains two databascs which arc uscd to storc thc dclinitions ol all
cxisting rcports that bclong to a particular Rcport Scrvcr. Thc storcd inlormation
includcs rcport namcs, dcscriptions, data sourcc conncction inlormation, crcdcntial
inlormation, paramctcrs, and cxccution propcrtics. Rcport Catalog also storcs sccurity
scttings and inlormation conccrning schcduling and dclivcring data.
Rcporting Scrviccs uscs two databascs, thc Rcport Scrvcr databasc and thc Rcport
Scrvcr tcmporary databasc, to scparatc pcrsistcnt data storagc lrom tcmporary storagc
rcquircmcnts. Thc databascs arc crcatcd togcthcr and bound by namc. 8y dclault, thc
databasc namcs arc reportserver and reportservertempdb. Thc lormcr is uscd to storc
Rcport Catalog, whilc thc lattcr is uscd as tcmporary storagc. (Thc Rcport Scrvcr
tcmporary databasc is uscd to storc scssion data, cachcd rcports, and work tablcs that
arc gcncratcd by thc rcport.)
Now that you arc lamiliar with thc componcnts ol Rcporting Scrviccs, you will lcarn
how to crcatc, dcploy, and dclivcr rcports.
Creating Reports
You usc 8usincss !ntclligcncc cvclopmcnt Studio to crcatc a rcport. 8! cvclopmcnt
Studio, introduccd in Chaptcr 23, is thc intcgratcd dcvclopmcnt cnvironmcnt built
on \isual Studio and dcsigncd lor thc 8! systcm dcvclopcr. To start 8! cvclopmcnt
Studio, click Start, All Programs, Microsoft SQL Server 2008, and choosc SQL
Server Business ntelligence Development Studio.
Thc lirst stcp in building a rcport is to crcatc a ncw projcct to which thc rcport
should bclong. To build a projcct, click Iile, sclcct New, and choosc Project. !n thc
New Project dialog box, sclcct thc Business ntelligence Projects loldcr in thc Project
Cha pt er 2 5: Mi c r os of t Pepor t i ng S er v i c es 609
types panc. Typc thc namc ol thc projcct and its location in thc Name and Location
tcxt boxcs, rcspcctivcly. Thc projcct in this cxamplc is callcd Report1, as you can scc in
Figurc 252.
!n thc Templates panc ol thc New Project dialog box (scc Figurc 252), you will scc
thrcc projcct tcmplatcs rclatcd to rcports. Thc Rcport Scrvcr Projcct tcmplatc crcatcs an
cmpty rcport and lcavcs you alonc to do thc rcst ol thc work. Thc Rcport Scrvcr Projcct
Vizard guidcs you during thc crcation phasc ol a ncw rcport. Thc Rcport Modcl
Projcct tcmplatc crcatcs a data modcl lor usc with Rcport 8uildcr.
ese/c||,, |e(c/||s :e/||:es /e(c/|s c/e |a||| as|s e|||e/ |e(c/| 3a||1e/ c/ |e(c/| |es|se/. |e(c/| 3a||1e/
c||cas ,ca |c 1c c1 |c: /e(c/||s, a|||ca| |sca|s cs,|||s c|ca| 1c|c|cse s|/a:|a/e cs1 c :/ec||cs c/ ae/|es
as|s ae/, |csaces, sa:| cs :9|. |e(c/| |es|se/ |e|s ,ca |a||1 c /e(c/| //cm s:/c|:|. || c//e/s mcs, mc/e
/ec|a/es /c/ :/ec||s /e(c/|s ||cs |e(c/| 3a||1e/ c//e/s.
!n this scction, you will usc thc Rcport Scrvcr Projcct Vizard tcmplatc to scc how to
crcatc a rcport. Thcrclorc, sclcct thc Report Server Project Wizard icon and click OK.
||qcre 1-1 |e |ea |/c(e:| 1|c|c |cs
610 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Creating Reports witb tbe Report Server Project Wizard
Thc Rcport Scrvcr Projcct Vizard wclcomc pagc introduccs thc stcps it takcs you
through to crcatc a rcport:
Sclcct thc data sourcc
csign thc qucry
Sclcct thc rcport typc
csign thc data in thc tablc
Spccily thc rcport layout
Spccily thc rcport stylc
Thc lollowing scctions dcscribc thcsc stcps as wcll as how to prcvicw thc crcatcd
rcport.
SeIect the Data Source
Thc data sourcc contains inlormation about thc conncction to thc sourcc databasc. Typc
thc namc ol thc ncw data sourcc on thc Select the Data Source pagc. (!n this cxamplc,
call thc data sourcc Source1.)
|e(c/||s :e/||:es :cs :/ec|e /e(c/|s //cm 1|//e/es| /e|c||csc| 1c|c|cses (:9| :e/|e/ cs1 0/c:|e c/
ma|||1|mess|csc| 1c|c|cses (/sc|,s|s :e/||:es. 0|| |3, 0|3t, cs1 //| 1c|c sca/:es :cs |e ase1, |cc. |e l,e
1/c(-1cas ||s| cs ||e Je/ect 0ete Jeatce (ce c||cas ,ca |c :|ccse cse c/ ||e 1|//e/es| 1c|c sca/:e |,(es.
Click Edit. Thc Connection Properties dialog box appcars, as shown in Figurc 253.
Typc cithcr localhost or thc namc ol your databasc scrvcr as thc scrvcr namc. !n thc
samc dialog box, choosc cithcr Use Windows Authentication or Use SQL Server
Authentication. Click thc Select or enter a database name radio button and choosc lrom
thc dropdown list onc ol thc databascs as thc data sourcc. 8clorc you click OK, click thc
Test Connection button to tcst thc conncction to thc databasc. n thc Select the Data
Source pagc, click Next.
Design the Query
Thc ncxt stcp is to dcsign a qucry that should bc cxccutcd against thc sclcctcd data
sourcc. n thc Design the Query pagc, you can cithcr typc (or pastc) an cxisting qucry
or usc thc Qucry 8uildcr componcnt to crcatc a qucry lrom scratch.
Cha pt er 2 5: Mi c r os of t Pepor t i ng S er v i c es 611
9ae/, 3a||1e/ :c//es(cs1s |c ||e s|m||c/ /::ess :cm(cses| ||c| ,ca :cs ase |c 1es|s ae/|es a|||ca|
|sca|e1e c/ ||e :9| |csace. ||s :cm(cses| |s ese/c||, |scas cs 93| (ae/, |, escm(|e.
For this lirst rcport, usc thc qucry givcn in xamplc 25.1.
XAMPL 25.1
SLCT dcpt_namc, cmp_lnamc, cmp_lnamc, job, cntcr_datc
FRM dcpartmcnt d J!N cmploycc c N d.dcpt_no - c.dcpt_no
J!N works_on w N w.cmp_no - c.cmp_no
VHR YAR(cntcr_datc) - 2007
RR 8Y dcpt_namc
Thc qucry in xamplc 25.1 sclccts data lor cmployccs who cntcrcd thcir job in 2007.
Thc rcsult sct ol thc qucry is thcn sortcd by dcpartmcnt namcs. Altcr that, click Next.
||qcre 1-1 |e tcsse:||cs |/c(e/||es 1|c|c |cs
612 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
|e(c/||s :e/||:es :|e:|s ||e scmes c/ ||e |c||es cs1 :c|amss ||s|e1 |s ||e ae/,. |/ ||e s,s|em /|s1s cs, s,s|cs
c/ semcs||: e//c/s, || 1|s(|c,s ||e :c//es(cs1|s messce |s ||e |cae/ (c/| c/ ||e a|s1ca (see ||a/e 1:-+.
SeIect the Report 7ype
Thc ncxt stcp in crcating a rcport is to sclcct thc rcport typc. You can choosc bctwccn
two rcport typcs:
Tabular Crcatcs a rcport in tabular lorm. Columns ol thc tablc corrcspond
to thc columns lrom thc SLCT list, whilc thc numbcr ol rows in thc tablc
dcpcnds on thc rcsult sct ol thc qucry.
Matrix Crcatcs a rcport in matrix lorm, which is similar to tablc lorm but
providcs lunctionality ol crosstabs. Unlikc thc tabular rcport typc, which has a
static sct ol columns, thc matrix rcport typc can bc dynamic.
||qcre 1-4 |e |es|s ||e 9ae/, (ce a||| cs e//c/ messce
Cha pt er 2 5: Mi c r os of t Pepor t i ng S er v i c es 613
ca s|ca|1 ase ||e mc|/|s /e(c/| |,(e a|ese|e/ ,ca acs| |c :/ec|e ae/|es ||c| :cs|c|s c/ec|e /as:||css,
sa:| cs /l c/ :|/.
Thc qucry in xamplc 25.1 docs not contain any aggrcgatc lunctions. Thcrclorc,
choosc thc tabular rcport typc.
Design the Data in the 7abIe
Altcr you click Next, thc Design the Table pagc appcars. This pagc allows you to
dccidc whcrc sclcctcd columns will bc placcd in your rcport. Thc Design the Table
pagc contains two groups ol liclds:


Thc Design the Table pagc also has thrcc vicws:
Pagc
Group
ctails
Availablc liclds arc thc columns lrom thc SLCT list ol your qucry. ach column
can bc movcd to onc ol thc vicws. To movc a licld to thc Pagc, Group, or ctails vicw,
sclcct thc licld and thcn click thc Page, Group, or Details button, rcspcctivcly. A
displayed f ield is an availablc licld that is assigncd to onc ol thc cxisting vicws.
Pagc vicw lists all columns that appcar at thc pagc lcvcl, and Group vicw lists
columns that arc uscd to group thc rcsulting sct ol thc qucry. ctails vicw is uscd to
display columns that appcar in thc dctail scction ol thc tablc. Figurc 255 shows thc
Design the Table pagc with thc dcsign ol thc tabular rcprcscntation lor thc rcsulting
sct. !n this cxamplc, thc dept_name column will appcar at thc pagc lcvcl, whilc thc job
column will bc uscd to group thc sclcctcd rows. Vhcn you havc choscn how to group
thc data in thc tablc, click Next.
|e c/1e/ c/ ||e :c|amss :cs |e |m(c/|cs|, es(e:|c||, /c/ /ca( ||ea. c :|cse ||e c/1e/ c/ ||e :c|amss, se|e:|
c :c|ams cs1 :||:| ||e a( c/ 1cas |a||cs |c ||e /|||.
614 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Specify the Report Layout
Thc ncxt stcp is to spccily thc layout ol your rcport. Thc Choose the Table Layout
pagc has scvcral options:
Stcppcd
8lock
!ncludc subtotals
nablc drilldown
!l you choosc Stepped, thc rcport will contain onc column lor cach licld, with
grouping liclds appcaring in hcadcrs to thc lclt ol columns lrom thc dctail licld. !n this
casc, thc group lootcr will not bc crcatcd. !l you includc subtotals with this layout typc,
thc subtotal is placcd in thc group hcadcr rows.
Thc Block option crcatcs a rcport that contains onc column lor cach licld, with
group liclds appcaring in thc lirst dctail row lor cach group. This layout typc has group
lootcrs only il thc nclude subtotals option is activatcd.
||qcre 1- |e |es|s ||e c||e (ce
Cha pt er 2 5: Mi c r os of t Pepor t i ng S er v i c es 615
Thc Enable drilldown option hidcs thc inncr groups ol thc rcport and cnablcs a
visibility togglc. (You can choosc Enable drilldown only il you sclcct thc Stepped option.)
To continuc, choosc Stepped and nclude subtotals and click Next.
Choose the Report StyIe
Thc ncxt stcp is to choosc a stylc lor your rcport. Thc Choose the Table Style pagc
allows you to sclcct a tcmplatc to apply stylcs such as lont, color, and bordcr stylc to thc
rcport. Thcrc arc scvcral dillcrcnt stylc tcmplatcs, such as Iorest, Corporate, and Bold.
Chosc Bold and click Next.
Altcr choosing a rcport stylc, thcrc is still onc intcrmcdiatc stcp il you arc crcating a
rcport lor thc lirst timc. !n this stcp callcd Choosc thc cploymcnt location, you must
choosc thc URL ol thc virtual dircctory ol thc rcport scrvcr and thc dcploymcnt loldcr
lor your rcports. For a rcport scrvcr running in nativc modc, usc thc path to thc rcport
scrvcr whcrc thc projcct is dcploycd, lor cxamplc http://scrvcrnamc/RcportScrvcr. For
a rcport scrvcr running in Sharcpoint intcgratcd modc, usc thc URL ol thc Sharcpoint
sitc to which thc projcct is dcploycd, lor cxamplc http://scrvcrnamc.
:9| :e/|e/ 1^^? |e(c/||s :e/||:es sa((c/| |ac mc1es c/ 1e(|c,mes| /c/ /e(c/| se/|e/ |ss|cs:es. sc|| |e mc1e
cs1 :|c/e(c|s| |s|e/c|e1 mc1e. |s sc|||e mc1e, a||:| |s 1e/ca||, c /e(c/| se/|e/ |s c s|cs1-c|cse c((||:c||cs
se/|e/ ||c| (/c||1es c|| ||ea|s, mcscemes|, (/c:ess|s, cs1 1e|||e/, c/ /e(c/|s. |s :|c/e(c|s| |s|e/c|e1
mc1e, c /e(c/| se/|e/ |e:cmes (c/| c/ c :|c/e|c|s| e| c((||:c||cs 1e(|c,mes|. |se/s c/ :|c/e|c|s| :e/|e/
:cs s|c/e /e(c/|s |s :|c/e|c|s| |||/c/|es cs1 c::ess ||em //cm ||e scme :|c/e|c|s| s||es ||e, ase |c c::ess c||e/
|as|sess 1c:ames|s.
Finally, you complctc thc wizard's work by providing a namc lor thc rcport. Also, you
can takc a look at thc rcport summary, whcrc all your prcvious stcps during thc crcation
ol thc rcport arc documcntcd. Click Iinish to linish thc wizard.
Preview the ResuIt Set
Vhcn you linish thc crcation ol your rcport using thc wizard, thcrc arc thrcc tabs in thc
Report Designer panc that you can usc to vicw thc crcatcd rcport in dillcrcnt lorms.
(!l thc Rcport csigncr panc isn't visiblc, click View and sclcct Designer.) Thc tabs
corrcspond to thc lollowing vicws:
Layout
ata
Prcvicw
616 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Thc Layout tab allows you to vicw and modily thc layout ol your rcport. Thc Layout
vicw consists ol thc lollowing scctions: body, pagc, hcadcr, and pagc lootcr. You can usc
thc Toolbox and Properties windows to manipulatc itcms in thc rcport. To vicw thcsc
windows, sclcct Toolbox or Properties Window in thc View mcnu. Usc thc Toolbox
window to sclcct itcms to placc thcm in onc ol thc scctions. ach itcm on thc rcport
dcsign surlacc contains propcrtics that can bc managcd using thc Properties window.
Click thc Data tab to vicw thc qucry. You can usc this vicw to display thc qucry
in two dillcrcnt lorms: using thc gcncric qucry dcsigncr or using thc graphical qucry
dcsigncr. Thc gcncric qucry dcsigncr consists ol a toolbar and two pancs: thc Query
panc shows thc qucry you usc to crcatc thc rcport, whilc thc Result panc shows thc
rcsult sct ol thc qucry. Thc graphical qucry dcsigncr consists ol a toolbar and lour
pancs: thc Diagram panc shows all tablcs that arc uscd in thc qucry, with corrcsponding
rclcrcntial constraints, thc Grid panc uscs thc Q8 componcnt to display thc qucry
in tabular lorm, thc SQL panc displays thc SLCT statcmcnt, and thc Result panc
shows thc rcsult sct ol thc statcmcnt.
To prcvicw thc rcport, click thc Preview tab. Thc rcport runs automatically, using
alrcady spccilicd propcrtics. Figurc 256 shows thc prcvicw lor thc rcport that was
dclincd in thc prcvious stcps.
||qcre 1-6 |e (/e||ea c/ ||e /e(c/|
Cha pt er 2 5: Mi c r os of t Pepor t i ng S er v i c es 617
Creating Parameterized Reports
A paramctcrizcd rcport is onc that uscs input paramctcrs to complctc rcport proccssing.
Thc paramctcrs arc thcn uscd to cxccutc a qucry that sclccts spccilic data lor thc rcport.
!l you dcsign or dcploy a paramctcrizcd rcport, you nccd to undcrstand how paramctcr
sclcctions allcct thc rcport.
Paramctcrs in Rcporting Scrviccs arc usually uscd to liltcr data. Thcy arc spccilicd
using thc known syntax lor variablcs (year, lor instancc). !l a paramctcr is spccilicd
in a qucry, a valuc must bc providcd to complctc thc SLCT statcmcnt or storcd
proccdurc that rctricvcs data lor a rcport.
You can dclinc a dclault valuc lor a paramctcr. !l all paramctcrs havc dclault valucs,
thc rcport will immcdiatcly display data whcn thc rcport is cxccutcd. !l at lcast onc
paramctcr docs not havc a dclault valuc, thc rcport will display data altcr thc uscr cntcrs
all paramctcr valucs.
Vhcn thc rcport is run in a browscr, thc paramctcr is displaycd in a box at thc top ol
thc rcport. Vhcn thc rcport is run in thc Preview modc, thc valuc ol thc paramctcr is
displaycd in thc corrcsponding box.
An cxamplc will bc uscd to show you how to crcatc a paramctcrizcd rcport. This
cxamplc dcscribcs only thosc stcps that arc dillcrcnt lrom thc stcps alrcady discusscd in
rclation to xamplc 25.1. Thc qucry uscd in this cxamplc, shown in xamplc 25.2,
sclccts data lrom thc AdventureWorksDW databasc. For this rcason, you havc to
sclcct and dclinc a ncw data sourcc. Thc spccilication ol thc ncw sourcc is idcntical
to thc spccilication ol thc sourcc callcd Source1, cxccpt that you choosc thc
AdventureWorksDW databasc instcad ol thc sample databasc.
XAMPL 25.2
US AdvcnturcVorksV,
SLCT t.MonthNumbcrlYcar AS month,
t.CalcndarYcar AS ycar,
p.ProductKcy AS product_id,
SUM(l.UnitPricc) AS sum_ol_salcs,
CUNT(l.UnitPricc) AS total_salcs
FRM imTimc t, imProduct p, Fact!ntcrnctSalcs l
VHR t.TimcKcy - l.rdcratcKcy AN
p.ProductKcy - l.ProductKcy
AN CalcndarYcar - Cycar
GRUP 8Y t.CalcndarYcar, t.MonthNumbcrlYcar, p.ProductKcy
RR 8Y 1,
618 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Thc qucry in xamplc 25.2 calculatcs thc numbcr and thc sum ol unit product
priccs. !t also groups thc rows according to thc list ol column namcs in thc GRUP
8Y clausc. Thc cxprcssion
CalcndarYcar - Cycar
in thc VHR clausc ol thc cxamplc spccilics that thc input paramctcr year in this
qucry is rclatcd to thc calcndar ycar lor which you want to qucry data.
This rcport is a matrix typc rcport. \alucs ol thc year column will bc assigncd to
thc Page vicw, valucs ol thc month column to thc Columns vicw, and valucs ol thc
product_id column to thc Rows vicw. Thc Detail vicw displays thc aggrcgatc valucs
SUM and CUNT.
To start thc rcport in Preview modc, typc thc valuc ol thc CalendarYear paramctcr
(2003, lor instancc) and click ViewReport.
Processing and Managing Reports
Rcport proccssing bcgins with a publishcd rcport dclinition, which includcs a qucry,
layout inlormation, and codc. Rcport and data proccssing togcthcr crcatc a datasct
with layout inlormation, which is storcd as an intcrmcdiatc lormat. Altcr proccssing is
complctc, rcports arc compilcd as a CLR asscmbly and cxccutcd on thc rcport scrvcr.
Thc intcrmcdiatc rcport lormat is uscd by thc rcport scrvcr lor thc lollowing rcport
lorms:
Cachcd rcport
Rcport snapshot
Caching mcans that a rcport is gcncratcd only lor thc lirst uscr who opcns it, and
thcrcaltcr is rctricvcd lrom thc cachc lor all subscqucnt uscrs who work with thc samc
rcport. As you probably gucsscd, caching shortcns thc timc to rctricvc lrcqucntly
acccsscd rcports.
A rcport snapshot is onc that contains data capturcd at a spccilic point in timc.
Thc main dillcrcncc bctwccn a rcport snapshot and othcr rcports is that othcr rcports
gcncrally contain qucry inlormation, whilc thc snapshot rcport contains thc rcsult sct ol
thc cxccutcd qucry.
/ /e(c/| ssc(s|c| |s ese/c||, ase1 |/ c /e(c/| |s |cse1 cs c |cs-/ass|s ae/,.
Cha pt er 2 5: Mi c r os of t Pepor t i ng S er v i c es 619
Gcncrally, you usc Rcport Managcr to managc rcports. Rcport Managcr is a
wcbbascd rcport acccss and managcmcnt tool that runs in Microsolt !ntcrnct xplorcr
or anothcr browscr. Thc lollowing managcmcnt lunctions, among othcrs, can bc
pcrlormcd using Rcport Managcr:

Managc data sourcc conncctions

Thc dcscription ol all managcmcnt lunctions providcd by Rcport Managcr can bc
lound in 8ooks nlinc.
Accessing and DeIivering Reports
8clorc you can usc or distributc a rcport, you havc to dcploy it. This can bc donc
by rightclicking thc crcatcd rcport and sclccting Deploy. Thc dcploymcnt proccss
contains scvcral stcps, which arc shown in thc Output panc:
8uild startcd: Projcct: R1, Conliguration: cbug
8uild complctc 0 crrors, 0 warnings
cploy startcd: Projcct: R1, Conliguration: cbug
cploying to http://localhost/RcportScrvcr
cploying data sourcc '/R1/samplc'.
cploying rcport '/R1/Rcport1'.
cploy complctc 0 crrors, 0 warnings
---------- 8uild: 1 succccdcd or uptodatc, 0 lailcd, 0 skippcd ----------
---------- cploy: 1 succccdcd, 0 lailcd, 0 skippcd ----------
Rcports can bc acccsscd and dclivcrcd using two mcthods:
n dcmand
Subscription bascd
Thc lollowing scctions dcscribc thcsc two mcthods.
Dn-Demand Reports
ndcmand acccss allows uscrs to sclcct thc rcports lrom a rcportvicwing tool. You
can usc Rcport Managcr or a browscr to vicw a rcport. This scction cxplains how you
can vicw ondcmand rcports using a browscr.
620 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Rcporting Scrviccs is a wcb application. For this rcason, all rcports arc organizcd
in a hicrarchical namcspacc and acccsscd through virtual dircctorics in Rcport Scrvcr.
Hcncc, within thc browscr, navigatc to thc homc pagc lor SQL Scrvcr Rcporting
Scrviccs (http://localhost/rcportscrvcr), which is thc dclault virtual dircctory lor Rcport
Scrvcr. Thc dclault virtual dircctory lor Rcport Managcr is http//localhost/Reports/.
(8oth dclault valucs can bc modilicd.)
To vicw a rcport on dcmand, sclcct thc rcport lrom thc corrcsponding loldcr
hicrarchy. !n this casc, Rcport Scrvcr crcatcs a tcmporary snapshot lor thc purposc ol
dclivcring thc rcport. Thc snapshot is discardcd altcr dclivcry.
Thcrc arc scvcral possibilitics lor running rcports on dcmand. Thc lirst onc is to
spccily that a rcport qucrics a corrcsponding data sourcc cach timc a uscr runs thc
rcport. !n this casc, a ncw instancc ol thc rcport is gcncratcd cach timc a ncw uscr
cxccutcs thc rcport.
!l you want to cnhancc pcrlormancc, cachcd rcports should bc your choicc. As
alrcady statcd, thc systcm crcatcs a cachcd copy ol thc rcport lor thc lirst uscr who
opcns it. All othcr uscrs who work with thc samc rcport rctricvc it lrom thc cachc.
Report Subscription
ndcmand rcporting rcquircs rcport sclcction cach timc you want to vicw a rcport's
rcsult. n thc othcr hand, subscriptionbascd acccss automatically gcncratcs and
dclivcrs rcports to a dcstination.
Rcporting Scrviccs supports two kinds ol subscriptions:
Pcrsonal (standard) subscriptions
atadrivcn subscriptions
PersonaI Subscriptions
A pcrsonal subscription usually consists ol spccilic paramctcrs lor paramctcrizcd rcports
as wcll as rcport prcscntation options and dclivcry options. You can usc dillcrcnt tools
to makc pcrsonal subscriptions. As an cxamplc, hcrc's how you can usc SQL Scrvcr
Managcmcnt Studio to crcatc a lilc sharc subscription:
1. !n bjcct xplorcr, cxpand thc rcport to which you want to subscribc. To do this,
you lirst havc to conncct to Reporting Services. Click thc Connect button and
sclcct Reporting Services. xpand thc corrcsponding instancc, cxpand thc loldcr
whcrc thc rcport is storcd, and cxpand thc rcport.
2. Rightclick thc Subscriptions loldcr and click New Subscription.
Cha pt er 2 5: Mi c r os of t Pepor t i ng S er v i c es 621
3. Sclcct Report Server Iile Share lrom thc Notify by list box.
4. Typc a lilcnamc lor thc rcport in thc Iile name tcxt box.
5. !n thc Path tcxt box, typc thc path ol thc loldcr that contains thc rcport.
6. Sclcct a lormat and a modc lrom thc Render format and Write mode list boxcs,
rcspcctivcly.
7. Typc a uscrnamc and password in thc corrcsponding tcxt boxcs.
|e :/ec||cs c/ cs e-mc|| sa|s:/|(||cs a||| :9| :e/|e/ /cscemes| :|a1|c |s s|m||c/, es:e(| /c/ ||e /c||ca|s
s|e(s. //cm ||e het/l, e, ||s| |cs, se|e:| keett Jetret f-e//, cs1 |s ||e le |es| |cs, |,(e ||e e-mc|| c11/ess.
Data-Driven Subscriptions
A datadrivcn subscription dclivcrs rcports to a list ol rccipicnts dctcrmincd at run
timc. This typc ol subscription dillcrs lrom a pcrsonal subscription in thc way it gcts
subscription inlormation: somc scttings lrom a data sourcc arc providcd at run timc,
and othcr scttings arc providcd lrom thc subscription dclinition. Static aspccts ol a
datadrivcn subscription includc thc rcport that is dclivcrcd, thc dclivcry cxtcnsion,
conncction inlormation to an cxtcrnal data sourcc that contains subscribcr data, and a
qucry. ynamic scttings ol thc subscription arc obtaincd lrom thc row sct produccd by
thc qucry, including a subscribcr list and uscrspccilic dclivcry cxtcnsion prclcrcnccs or
paramctcr valucs.
ConcIusion
Rcporting Scrviccs is thc SQL Scrvcrbascd cntcrprisc rcporting tool. To crcatc a
rcport, you can usc thc Rcport Scrvcr Projcct Vizard, Rcport 8uildcr, or Rcport
csigncr. Thc dclinition ol a rcport, which compriscs thc corrcsponding qucry, layout
inlormation, and codc, is storcd using thc XMLbascd Rcport clinition Languagc
(RL). Rcporting Scrviccs proccss thc rcport dclinition into onc ol thc standard
lormats, such as HTML or PF.
Rcports can bc acccsscd on dcmand or dclivcrcd bascd on a subscription. Vhcn you
cxccutc a rcport on dcmand, a ncw instancc ol thc rcport will usually bc gcncratcd cach
timc you run thc rcport. Subscriptionbascd rcports can bc cithcr standard (pcrsonal)
or data drivcn. Rcports bascd on a pcrsonal subscription usually consist ol spccilic
paramctcrs as wcll as rcport prcscntation options and dclivcry options. A datadrivcn
subscription dclivcrs rcports to a list ol rccipicnts dctcrmincd at run timc.
Thc ncxt chaptcr dcscribcs optimization tcchniqucs lor busincss intclligcncc.
622 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
xercises
.25.1
Gct thc cmploycc numbcrs and namcs lor all clcrks. Crcatc a rcport in thc matrix rcport
typc using this qucry. Usc Rcport Managcr to vicw a rcport.
.25.2
Usc thc sample databasc and gct thc budgcts ol projccts and projcct namcs bcing
workcd on by cmployccs in thc Rcscarch dcpartmcnt that havc an cmploycc numbcr
25000. Crcatc a rcport in thc tablc rcport typc using this qucry. Usc a browscr to vicw
thc rcport.
In 7bis Cbapter
Data Partitioning
Star Scbema uery
Dptimization
ptlmlzlng Jcchnlqucs
lor Iuslncss Intclllgcncc
Cbapter 26
Copyright 2008 by The McGraw-Hill Companies. Click here for terms of use.
624 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
T
his chaptcr dcscribcs two optimizing tcchniqucs in rclation to RLAP. !n
othcr words, thcsc tcchniqucs can bc applicd only to rclational storagc ol
multidimcnsional data. Thc lirst part ol this chaptcr discusscs whcn it is
rcasonablc to storc all cntity instanccs in a singlc tablc and whcn it is bcttcr, bccausc
ol pcrlormancc rcasons, to partition thc tablc's data. Altcr a gcncral introduction, thc
ways how to partition data will bc givcn. 8csidcs guidclincs lor partitioning, this scction
dcscribcs thc improvcmcnts in SQL Scrvcr 2008 conccrning this tcchniquc.
!n thc sccond part ol this chaptcr, thc tcchniquc callcd star schcma qucry optimization
will bc cxplaincd in dctail. Thc advantagcs ol thc tcchniquc, as wcll as usc ol bitmap liltcrs,
will bc givcn.
Data Partitioning
Thc casicst and most natural way to dcsign an cntity is to usc a singlc tablc. Also, il all
instanccs ol an cntity bclong to a tablc, you don't nccd to dccidc whcrc to storc its rows
physically, bccausc thc databasc systcm docs this lor you. For this rcason thcrc is no
nccd lor you to do any administrativc tasks conccrning storagc ol tablc data, il you don't
want to.
n thc othcr hand, onc ol thc most lrcqucnt causcs ol poor pcrlormancc in rclational
databasc systcms is contcntion lor data that rcsidcs on a singlc !/ dcvicc. This is
cspccially truc il you havc onc or morc vcry largc tablcs with scvcral hundrcd thousands,
or millions ol rows. !n that casc, on a systcm with multiplc CPUs, partitioning thc tablc
can lcad to bcttcr pcrlormancc through parallcl opcrations.
Using data partitioning you can dividc vcry largc tablcs (and indiccs, too) into smallcr
parts that arc casicr to managc. !l thc partitioning is donc, many opcrations can bc donc
in parallcl, such as loading data, backup and rccovcry, and qucry proccssing.
Partitioning also improvcs thc availability ol thc cntirc tablc. 8y placing cach partition
on its own disk, you can still acccss data, cvcn il onc or morc disks arc unavailablc. !n
that casc all data in thc availablc partitions can bc uscd lor rcad and writc opcrations.
Thc samc is truc lor maintcnancc opcrations.
!l a tablc is partitioncd, thc qucry optimizcr can rccognizc whcn thc scarch condition
in a qucry rclcrcnccs only rows in ccrtain partitions and thcrclorc limits its scarch to
thosc partitions. That way, you can achicvc signilicant pcrlormancc gains.
Ways to Partition Your Data
A tablc can bc partitioncd using any column ol thc tablc. Such a column is callcd thc
partition key. (!t is also possiblc to usc a group ol columns lor thc particular partition
kcy.) Thc valucs ol thc partition kcy arc uscd to partition tablc rows to dillcrcnt
lilcgroups.
Cha pt er 2 6: Opt i mi z i ng Tec hni ques f or 8us i nes s | nt el l i genc e 625
8csidc partition kcy, thcrc arc two othcr important notions in rclation to partitioning:
partition schcmc and partition lunction. Thc partition schcmc maps thc tablc rows to
onc or morc lilcgroups. Thc way this mapping is donc is dcscribcd using thc partitioning
lunction. !n othcr words, thc partition lunction dclincs thc algorithm that is uscd to
dircct thc rows to thcir physical location.
atabasc nginc supports only onc lorm ol partitioning, which is rangc partitioning.
Fange partitioning dividcs tablc rows into dillcrcnt partitions bascd on thc valuc ol thc
partition kcy. Hcncc, by applying rangc partitioning you will always know in which
partition a particular row will bc storcd.
3es|1es /cse (c/||||cs|s, ||e/e c/e se|e/c| c||e/ (c/||||cs /c/ms. 0se c/ ||em |s :c||e1 |cs| (c/||||cs|s.
|s :cs|/cs| |c /cse (c/||||cs|s, |cs| (c/||||cs|s (|c:es /cas cse c/|e/ csc||e/ |s (c/||||css |, c((|,|s c
|cs||s /as:||cs |c ||e (c/||||cs |e,. ||s (c/||||cs /c/m |s sc| sa((c/|e1 |, |c|c|cse |s|se.
8clorc wc dclinc rangc partitioning, wc will look at thc stcps lor crcating partitioncd
tablcs.
Steps for Creating Partitioned 7abIes
8clorc you start to partition databasc tablcs, you havc to complctc thc lollowing stcps:
Sct partition goals
ctcrminc partitioning kcy and numbcr ol partitions

Crcatc partition lunction and partition schcmc
Crcatc partitioncd indiccs (il ncccssary)
All ol thcsc stcps will bc cxplaincd in thc lollowing scctions.
Set Partition CoaIs
Partition goals dcpcnd on thc typc ol applications that acccss thc tablc that should bc
partitioncd. Thcrc arc many dillcrcnt goals, and cach ol thcm could bc a singlc rcason
to partition a tablc:
!mprovcd pcrlormancc lor individual qucrics
Rcduccd contcntion
!mprovcd data availability
626 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
!l thc primary goal ol tablc partitioning is improvcd pcrlormancc lor individual
qucrics, distributc all tablc rows cvcnly. Thc rcason is that thc databasc systcm docsn't
havc to wait lor data rctricval lrom a partition that has morc rows than othcr partitions.
Also, il such qucrics acccss data by pcrlorming tablc scan against signilicant portions ol
a tablc, partition thc tablc rows only. (Thc partition ol thc corrcsponding indcx will just
makc thc ovcrhcad in such a casc.)
ata partitioning can rcducc contcntion whcn many simultancous qucrics pcrlorm
indcx scan to rcturn just a lcw rows lrom a tablc. !n this casc, partition thc tablc and
indcx with a partition schcmc that allows cach qucry to climinatc unnccdcd partitions
lrom its scan. To rcach this goal, start by invcstigating which qucrics acccss which
parts ol thc tablc. Thcn partition tablc rows so that dillcrcnt qucrics acccss dillcrcnt
partitions.
Partitioning improvcs thc availability ol thc databasc. 8y placing cach partition on
its own lilcgroup and locating cach lilcgroup on its own disk, you can incrcasc thc data
availability, bccausc il onc disk lails and is no longcr acccssiblc, only thc data in that
partition is unavailablc. Vhilc thc systcm administrator scrviccs thc corruptcd disk,
othcr uscrs can continuc to acccss data lrom thc othcr partitions ol thc tablc.
Determine Partitioning key and Number of Partitions
A tablc can bc partitioncd using any tablc column. Thc valucs ol thc partition kcy arc
uscd to partition tablc rows to dillcrcnt lilcgroups. For thc bcst pcrlormancc, cach
partition should bc storcd in a scparatc lilcgroup, and cach lilcgroup should bc storcd
on onc scparatc disk dcvicc. 8y sprcading thc data across scvcral disk dcviccs, you can
balancc thc !/ and improvc qucry pcrlormancc, availability, and maintcnancc.
You should partition thc data ol a tablc using a column that docs not lrcqucntly
changc. !l thc partitioning is donc by a column that changcs oltcn, any updatc
opcration ol that column can lorcc thc systcm to movc thc modilicd rows lrom onc
partition to thc othcr, and this could bc timc consuming.
Create a IiIegroup for ach Partition
To achicvc bcttcr pcrlormancc, highcr data availability, and casicr maintcnancc, you will
usc dillcrcnt lilcgroups to scparatc tablc data. Thc numbcr ol lilcgroups dcpcnds mostly
on thc hardwarc you havc. Vhcn you havc multiplc CPUs, partition your data so that
cach CPU can acccss data on onc disk dcvicc. !l atabasc nginc can proccss multiplc
partitions in parallcl, thc proccssing timc ol your application will bc signilicantly rcduccd.
ach data partition must map to a lilcgroup. To crcatc a lilcgroup you usc cithcr thc
CRAT ATA8AS or ALTR ATA8AS statcmcnt. Thc lollowing cxamplc
shows thc crcation ol a databasc callcd test_partitioned with onc primary lilcgroup and
two othcr lilcgroups.
Cha pt er 2 6: Opt i mi z i ng Tec hni ques f or 8us i nes s | nt el l i genc e 627
3e/c/e ,ca :/ec|e ||e |es|_(c/||||cse1 1c|c|cse ,ca |c|e |c :|cse ||e (|,s|:c| c11/esses c/ c|| .m1/ cs1 .s1/
/||es |s |scm(|e 1.! c::c/1|s |c ||e /||e s,s|em ,ca |c|e cs ,ca/ :cm(a|e/.
XAMPL 26.1
US mastcr,
CRAT ATA8AS tcst_partitioncd
N PR!MARY
( NAM-'My8_Primary',
F!LNAM-
'd:\mssql\PT_Tcst_Partitioncd_Rangc_dl.mdl',
S!Z-2000,
MAXS!Z-5000,
F!LGRVTH-1 ),
F!LGRUP My8_FG1
( NAM - 'FirstFilcGroup',
F!LNAM -
'd:\mssql\My8_FG1.ndl',
S!Z - 1000M8,
MAXS!Z-2500,
F!LGRVTH-1 ),
F!LGRUP My8_FG2
( NAM - 'SccondFilcGroup',
F!LNAM -
'l:\mssql\My8_FG2.ndl',
S!Z - 1000M8,
MAXS!Z-2500,
F!LGRVTH-1 ),
!n xamplc 26.1 wc crcatc a databasc callcd test_partitioned, which contains
a primary lilcgroup MyDB_Primary and two othcr lilcgroups: MyDB_IG1 and
MyDB_IG2. Thc MyDB_IG1 lilcgroup is storcd on thc drivc, whilc thc
MyDB_IG2 lilcgroup is storcd on thc F drivc.
!n casc you want to add lilcgroups to an cxisting databasc, usc thc ALTR
ATA8AS statcmcnt. xamplc 26.2 shows how to crcatc anothcr lilcgroup lor thc
test_partitioned databasc.
628 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
XAMPL 26.2
US mastcr,
ALTR ATA8AS tcst_partitioncd
A F!LGRUP My8_FG3
G
ALTR ATA8AS tcst_partitioncd
A F!L
( NAM - 'ThirdFilcGroup',
F!LNAM -
'G:\mssql\My8_FG3.ndl',
S!Z - 1000M8,
MAXS!Z-2500,
F!LGRVTH-1)
T F!LGRUP My8_FG3,
!n xamplc 26.2 wc usc thc ALTR ATA8AS statcmcnt to crcatc an additional
lilcgroup callcd MyDB_IG3. Vith thc sccond ALTR ATA8AS statcmcnt wc
add a ncw lilc to thc crcatcd lilcgroup. Noticc that thc T F!LGRUP option
spccilics thc namc ol thc lilcgroup to which thc ncw lilc will bc addcd.
Create Partition Iunction and Partition Scheme
Thc ncxt stcp altcr crcating lilcgroups is to crcatc thc partition lunction. Thc partition
lunction is crcatcd with thc CRAT PART!T!N FUNCT!N statcmcnt. Thcrc
arc two lorms ol this statcmcnt, dcpcnding on thc partitioning typc. Thc syntax ol thc
CRAT PART!T!N FUNCT!N conccrning this rangc partitioning typc is as
lollows:
CRAT PART!T!N FUNCT!N lunction_namc(param_typc)
AS RANG | LFT ] R!GHT |
FR \ALUS ( | boundary_valuc | ,...n | | )
function_name dclincs thc namc ol thc partition lunction, whilc param_type spccilics
thc data typc ol thc partition kcy. boundary_value spccilics onc or morc boundary valucs
lor cach partition ol a partitioncd tablc or indcx that uscs thc partition lunction.
Thc CRAT PART!T!N FUNCT!N supports two lorms ol thc RANG
optionRANG LFT and RANG R!GHT. RANG LFT dctcrmincs that
thc boundary condition is thc uppcr boundary in thc lirst partition. According to this,
RANG R!GHT spccilics that thc boundary condition is thc lowcr boundary in thc
last partition. !l not spccilicd, RANG LFT is thc dclault.
Cha pt er 2 6: Opt i mi z i ng Tec hni ques f or 8us i nes s | nt el l i genc e 629
8clorc thc partition lunction can bc dclincd, you havc to spccily thc tablc that will
bc uscd lor partitioning. !n this chaptcr's cxamplcs thc orders tablc will bc uscd. Thc
lollowing cxamplc crcatcs thc tablc. (Chcck lirst, whcthcr your sample databasc alrcady
contains thc orders tablc. !l so, plcasc drop it.)
XAMPL 26.3
US samplc,
CRAT TA8L ordcrs
(ordcrid !NTGR NT NULL,
ordcrdatc AT,
shippcddatc AT,
lrcight moncy),
G
dcclarc Ci int , Cordcr_id intcgcr
dcclarc Cordcrdatc datctimc
dcclarc Cshippcd_datc datctimc
dcclarc Clrcight moncy
sct Ci - 1
sct Cordcrdatc - gctdatc()
sct Cshippcd_datc - gctdatc()
sct Clrcight - 100.00
whilc Ci 1000001
bcgin
inscrt into ordcrs (ordcrid, ordcrdatc, shippcddatc, lrcight)
valucs( Ci, Cordcrdatc, Cshippcd_datc, Clrcight)
sct Ci - Ci1
cnd
Thc CRAT TA8L statcmcnt in xamplc 26.3 crcatcs thc orders tablc, whilc
thc subscqucnt batch loads onc million rows in that tablc.
Thc lollowing cxamplc shows thc dclinition ol thc partition lunction lor thc orders
tablc with 1000000 rows.
XAMPL 26.4
US tcst_partitioncd,
CRAT PART!T!N FUNCT!N myRangcPF1 (int)
AS RANG LFT FR \ALUS (500000) ,
630 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Thc CRAT PART!T!N FUNCT!N myRangePI1 spccilics that thcrc will
bc two partitions and that thc boundary valuc is 500000. This mcans that all valucs
ol thc partition kcy that arc smallcr than 500000 will bc placcd in thc lirst partition,
whilc all valucs grcatcr than 500000 will bc storcd in thc sccond partition. (Notc that
thc boundary valuc is rclatcd to thc valucs in thc partition kcy, which in our cxamplc
is thc column orderid ol thc orders tablc. As you will scc, wc spccily thc namc ol thc
partition kcy in thc corrcsponding CRAT TA8L statcmcnt.)
Thc crcatcd partition lunction is usclcss il wc don't associatc it with spccilic
lilcgroups. This proccss is callcd partition schcmc, and you usc thc CRAT
PART!T!N SCHM statcmcnt to spccily thc association bctwccn a partition
schcmc and thc corrcsponding lilcgroups. Thc lollowing cxamplc shows thc crcation ol
thc partition schcmc lor thc partition lunction in xamplc 26.4.
XAMPL 26.5
US tcst_partitioncd,
CRAT PART!T!N SCHM myRangcPS1
AS PART!T!N myRangcPF1
T (My8_FG1, My8_FG2),
xamplc 26.5 crcatcs thc partition schcmc callcd myRangePS1. According to this
schcmc all valucs to thc lclt ol thc boundary valuc (i.c., all valucs 500000) will bc
storcd in thc MyDB_IG1 lilcgroup. Also, all valucs to thc right ol thc boundary valuc
will bc storcd in thc MyDB_IG2 lilcgroup.
|es ,ca 1e/|se c (c/||||cs s:|eme, ,ca mas| |e sa/e |c s(e:|/, c /||e/ca( /c/ ec:| (c/||||cs, e|es |/ ma|||(|e
(c/||||css a||| |e s|c/e1 cs ||e scme /||e/ca(.
Thc crcation ol a partitioncd tablc is slightly dillcrcnt lrom thc crcation ol a
nonpartitioncd onc. As you might gucss, thc CRAT TA8L statcmcnt must
contain thc namc ol thc partition schcmc and thc namc ol thc tablc column, which
will bc uscd as partition kcy. Thc lollowing cxamplc shows thc cnhanccd lorm ol thc
CRAT TA8L statcmcnt, which is uscd to dclinc partitioning ol thc orders tablc.
XAMPL 26.6
US tcst_partitioncd,
CRAT TA8L ordcrs
(ordcrid !NTGR NT NULL,
ordcrdatc ATT!M,
Cha pt er 2 6: Opt i mi z i ng Tec hni ques f or 8us i nes s | nt el l i genc e 631
shippcddatc ATT!M,
lrcight moncy)
N myRangcPS1 (ordcrid),
Thc N clausc at thc cnd ol thc CRAT TA8L statcmcnt is uscd to spccily thc
alrcadydclincd partition schcmc (scc xamplc 26.5). Using this schcmc, thc spccilicd
partition schcma tics togcthcr thc column ol thc tablc (orderid) with thc partitioning
lunction whcrc thc data typc (int) ol thc partition kcy is spccilicd (scc xamplc 26.4).
Creation of Partitioned Index
Vhcn you partition tablc data, thc indiccs that arc associatcd with that tablc can bc
partitioncd, too. You can partition tablc indiccs using thc cxisting partition schcma
lor that tablc or a dillcrcnt onc. Vhcn both thc indiccs and thc tablc usc thc samc
partitioning lunction and thc samc partitioning columns (in thc samc ordcr), thc tablc
and indcx arc said to bc aligncd. Vhcn a tablc and its indiccs arc aligncd, thc databasc
systcm can movc partitions in and out ol partitioncd tablcs vcry cllcctivcly, bccausc thc
partitioning ol both databasc objccts is donc with thc samc algorithm. For this rcason,
in thc most practical cascs it is rccommcndcd that you usc aligncd indiccs.
Thc lollowing cxamplc shows thc crcation ol a clustcrcd indcx lor thc orders tablc.
This indcx is aligncd, i.c., it is partitioncd using thc partition schcmc ol thc orders tablc.
XAMPL 26.7
US tcst_partitioncd,
CRAT UN!QU CLUSTR !NX C!_ordcrs
N ordcrs(ordcrid)
N myRangcPS1(ordcrid),
As you can scc lrom xamplc 26.7, thc crcation ol thc partitioncd indcx lor thc
orders tablc is donc using thc cnhanccd lorm ol thc CRAT !NX statcmcnt.
This lorm ol thc CRAT !NX statcmcnt contains an additional N clausc that
spccilics thc partitioning schcmc. !l you want to align thc indcx with thc tablc, spccily
thc samc partition schcmc as lor thc corrcsponding tablc. (Thc lirst N clausc is thc
part ol thc standard syntax ol thc CRAT !NX statcmcnt and spccilics thc
column lor partitioning.)
CoIIocating 7abIes
8csidcs partitioning ol a tablc togcthcr with thc corrcsponding indiccs, atabasc nginc
also supports thc partitioning ol two tablcs using thc samc partition lunction. This partition
lorm mcans that rows ol both tablcs that havc thc samc valuc lor thc partitioning kcy arc
storcd togcthcr on a spccilic location. This conccpt ol data partitioning is callcd collocation.
632 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Supposc that, bcsidcs thc orders tablc, thcrc is also thc order_details tablc, which
contains zcro, onc, or morc rows with ordcrs lor cach uniquc ordcr numbcr in thc
orders tablc. !l you partition both thc tablcs using thc samc partition lunction on thc
join columns orders.orderid and order_details.orderid, thc rows ol both tablcs with
thc samc valuc lor thc orderid columns will bc storcd togcthcr on thc disk. Supposc
that thcrc is a uniquc ordcr with thc idcntilication numbcr 49031 in thc orders tablc
and 5 corrcsponding rows in thc order_details tablc. !n thc casc ol collocation, all six
rows will bc storcd sidc by sidc on thc disk. (Thc samc proccdurc will bc applicd to all
rows ol thcsc tablcs with thc samc valuc lor thc orderid column.)
SL Server 2008 and Data Partitioning
SQL Scrvcr 2008 has thc lollowing improvcmcnts in rclation to data partitioning:

opcrations arc cxccutcd
Parallcl cxccution lor qucrics on partitioncd tablcs using multiplc thrcads
!mprovcd cditing ol inlormation conccrning partitioncd tablcs
Thc lollowing scctions discuss thcsc lcaturcs.
New Partition-Aware Seek Operation
!n SQL Scrvcr 2008, thc intcrnal rcprcscntation ol a partitioncd tablc is changcd so
that thc tablc appcars to thc qucry proccssor as a compositc (multicolumn) indcx with
thc partitioncd column as thc lcading column. (This column, callcd partitionedD,
is a hiddcn computcd column uscd intcrnally to rcprcscnt thc ! ol thc partition
containing a spccilic row.)
For cxamplc, supposc thcrc is thc tab tablc with thrcc columns col1, col2 and col3.
(col1 is uscd to partition thc tablc, whilc thc col2 column has a clustcrcd indcx.) !n
SQL Scrvcr 2008, such a tablc is trcatcd intcrnally as a nonpartitioncd tablc with thc
lollowing schcma:
tab (partition!, col1, col2 col3)
and with a clustcrcd indcx on thc lollowing compositc kcy (partitioncd, col2). This
allows thc qucry optimizcr to pcrlorm scck opcrations bascd on thc computcd column
partitionD on any partitioncd tablc or indcx.
Cha pt er 2 6: Opt i mi z i ng Tec hni ques f or 8us i nes s | nt el l i genc e 633
That way, thc pcrlormancc ol a signilicant numbcr ol qucrics on partition tablcs can
bc improvcd bccausc thc partition climination is donc carlicr.
ParaIIeI xecution for Queries
!n SQL Scrvcr 2005, onc thrcad is allocatcd pcr partition whcn multiplc partitions
arc qucricd. !n othcr words, cach qucry, which is uscd ovcr partitioncd tablcs cannot
bc parallclizcd. (For dclinition ol parallcl qucrics, scc Chaptcr 15.) This can causc
pcrlormancc problcms on systcms with many CPUs, il thc tablc schcma has lcss
partitions than thcrc arc CPUs. !n that casc not all thc CPUs will bc uscd to proccss
thc qucry.
SQL Scrvcr 2008 providcs two qucry cxccution stratcgics lor parallcl qucry plans on
partitioncd objccts: a singlcthrcadpcrpartition stratcgy and a multiplcthrcadpcr
partition stratcgy.
!n thc singlcthrcadpcrpartition stratcgy, thc qucry optimizcr assigns onc thrcad
pcr partition to cxccutc a parallcl qucry plan that acccsscs multiplc partitions. (This
corrcsponds to thc bchavior in SQL Scrvcr 2005 and is thc dclault in SQL Scrvcr
2008.) nc partition is not sharcd bctwccn multiplc thrcads, but multiplc partitions can
bc proccsscd in parallcl.
Thc multiplcthrcadspcrpartition stratcgy assigns multiplc thrcads pcr partition
rcgardlcss ol thc numbcr ol partitions to bc acccsscd. !n othcr words, all availablc
thrcads start at thc lirst partition to bc acccsscd and scan lorward. As cach thrcad
rcachcs thc cnd ol thc partition, it movcs to thc ncxt partition and bcgins scanning
lorward. Thc thrcad docs not wait lor thc othcr thrcads to linish bclorc moving to thc
ncxt partition.
|e ma|||(|e-||/ec1s-(e/-(c/||||cs s|/c|e, |s esc||e1 |, as|s |/c:e /|c 1++^. (/c:e /|cs c/e ase1 |c
|em(c/c/||, se| s(e:|/|: se/|e/ :|c/c:|e/|s||:s c/ |c sa||:| c// c (c/||:a|c/ |e|c||c/. c se| c |/c:e /|c, ase ||e
|3tt :cmmcs1 a||| ||e |/t|0| c(||cs. |e /c||ca|s :cmmcs1 esc||es ||e |/c:e /|c 1++^.
|3tt |/t|0| (1++^.
Vhich stratcgy to choosc dcpcnds on your cnvironmcnt. Thc lormcr stratcgy is
rccommcndcd il qucrics arc !/bound and includc morc partitions than thc dcgrcc ol
parallclism. Thc lattcr stratcgy is rccommcndcd in thc lollowing cascs:
Partitions arc stripcd cvcnly across many disks.
Your qucrics usc lcwcr partitions than thc numbcr ol availablc thrcads.

634 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
nhancements Concerning Partition Information
SQL Scrvcr 2008 providcs thc lollowing cnhanccd partitioning inlormation:
An optional attributc callcd Partitioned, which indicatcs that an opcrator
(scck, scan, inscrt, updatc or dclctc), is pcrlormcd on a partitioncd tablc.
nhanccd inlormation conccrning thc partitionD computcd column.
Summary inlormation that providcs a total count ol thc partitions acccsscd.
CuideIines for Partitioning 7abIes and Indices
Thc lollowing suggcstions arc guidclincs lor partitioning tablcs and indiccs:
o not partition cvcry tablc. Partition only thosc tablcs that arc acccsscd most
lrcqucntly.

hundrcd thousands ol rows.
For bcst pcrlormancc, usc partitioncd indiccs to rcducc contcntion bctwccn
scssions.
8alancc thc numbcr ol partitions with thc numbcr ol proccssors on your systcm.
!l it is not possiblc lor you to cstablish thc 1:1 rclationship bctwccn thc numbcr
ol partitions and thc numbcr ol proccssors, spccily thc numbcr ol partitions as a
multiplc lactor ol thc numbcr ol proccssors.
o not partition thc data ol a tablc by a column that changcs lrcqucntly. !l thc
partitioning is donc by a column that changcs oltcn, any updatc opcration ol that
anothcr, and this could bc vcry timc consuming.
For optimal pcrlormancc, partition thc tablcs to incrcasc parallclism, but do not
Star Scbema uery Dptimization
As you alrcady know lrom Chaptcr 22, thc star and snowllakc schcmas arc two
gcncral lorms lor structuring data in a data warchousc. 8oth thc schcmas havc usually
onc lact tablc, which is conncctcd with scvcral dimcnsion tablcs. Thc lact tablc can
havc 100 million rows or morc, whilc dimcnsion tablcs contain up to scvcral million
rows. Gcncrally, in dccision support qucrics, scvcral dimcnsion tablcs arc joincd with
Cha pt er 2 6: Opt i mi z i ng Tec hni ques f or 8us i nes s | nt el l i genc e 635
thc corrcsponding lact tablc. Signilicant pcrlormancc gains can bc achicvcd, il thc
qucry optimizcr can rccognizc such qucrics and apply spccial tcchniqucs to it. Thc
usc ol thcsc tcchniqucs by thc qucry optimizcr arc gcncrally callcd star schcma qucry
optimization.
/|||ca| s|c/ s:|emc ae/, c(||m|cc||cs acs sa((c/|e1 |, :9| :e/|e/ 1^^: ||e mc|s es|cs:emes|s c/e
|m(|emes|e1 |s :9| :e/|e/ 1^^?.
Lct us usc an cxamplc to cxplain how star schcma qucry optimization works.
XAMPL 26.8
US AdvcnturcVorksV,
SLCT ProductAltcrnatcKcy
FRM Fact!ntcrnctSalcs l J!N imTimc t N l.rdcratcKcy - t.TimcKcy
J!N imProduct d N d.ProductKcy - l.ProductKcy
VHR CalcndarYcar 8TVN 2003 AN 2004
AN ProductAltcrnatcKcy L!K '8K'
GRUP 8Y ProductAltcrnatcKcy, CalcndarYcar,
|scm(|e 1.? s|cas (as| c ese/c| /c/m c/ c ae/,, a|e/e s|c/ s:|emc ae/, c(||m|cc||cs :cs |e c((|| e1. (|| |s
sc| sc|1 ||c| ||e ae/, c(||m|ce/ a||| c((|, |||s me:|cs|sm |c ||e ae/, c|c|e.
Thc cxamplc abovc is a qucry bascd upon onc ol thc star schcmas ol thc
AdventureWorksDW databasc. Thc qucry optimizcr ol SQL Scrvcr 2008 dctccts thc
star schcma and idcntilics thc lact tablc (IactnternetSales) and thc corrcsponding
dimcnsion tablcs (DimTime and DimProduct). !l thc rcsult scts ol corrcsponding join
opcrations bctwccn thc lact tablc and cach dimcnsion tablc contain small or mcdium
numbcr ol rows, thc qucry optimizcr applics so callcd bitmap liltcrs to apply scmijoin
opcration carly on thc qucry. (For thc dclinition ol scmijoin, scc Chaptcr 6.)
|c sc| m|s |||mc( /|||e/s a||| |||mc( |s1|:es| 3||mc( /|||e/s c/e cs |s-memc/, s|/a:|a/e ||c| |s ase1 /c/
es|cs:|s (e//c/mcs:e 1a/|s ||e ese:a||cs c/ c ae/,. (3||mc( |s1|:es c/e (e/s|s|es| s|/a:|a/es, a||:| c/e
ase1 |s 3| cs cs c||e/sc|||e |c 3
+
-|/ee s|/a:|a/es. :9| :e/|e/ 1cess| sa((c/| |||mc( |s1|:es.
636 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Thc primary rolc ol thc bitmap liltcr is to spccd up parallcl plans by doing scmijoin
rcduction, bclorc rows arc passcd through thc opcrator conccrning parallcl cxccution.
(8itmap liltcrs arc not uscd in scrial plans.)
3||mc( /|||e/s :cs |e ase1 a||| |ac (/c:ess|s |e:|s|aes /c/ (c|s. |cs| (c|ss cs1 /e/e (c|ss.

SQL Scrvcr 2008 supports thc lollowing cnhanccmcnts in rclation to bitmap liltcrs:




8itmap liltcrs arc visiblc in thc XML lorm ol thc cxccution plan (scc Chaptcr 20). !n
this casc thc XML attributcs PhysicalOP and LogicalOP contains thc valucs "8itmap"
and "8itmap Crcatc", rcspcctivcly. (Scc Chaptcr 27 lor thc dclinition ol XML attributcs.)
!n contrast to SQL Scrvcr 2005, thc qucry optimizcr ol SQL Scrvcr 2008 can
dynamically changc thc position ol a bitmap liltcr. (Pcrlormancc advantagcs can bc
achicvcd, il bitmap liltcrs arc pushcd dccpcr into qucry trcc.) Also, scvcral bitmap liltcrs
can now bc applicd lor a qucry.
Qucry optimizcr's dccisions in rclation to join optimization cannot bc inllucnccd by
uscrs. !n othcr words, thcrc is no systcm proccdurc (or known tracc llag), which can bc
uscd to dcactivatc (or rcactivatc) this lcaturc.
|e 1e:|s|cs c/ /|:/csc/| |c 1e|||e/ s|c/ s:|emc ae/, c(||m|cc||cs a|||ca| ||e (css||||||, /c/ ase/s |c 1ec:|||c|e
||, |cs ||s c1|cs|ces cs1 1|sc1|cs|ces. |e mc|s c1|cs|ce |s ||c| ||e ||es sc|a||cs 1ces sc| es|cs:e ||e
:cm(|es||, c/ ||e s,s|em. 0s ||e c||e/ |cs1, ase/s s|ca|1 |c|e ||e c||e/sc|||e |c 1ec:|||c|e || /c/ c ae/,, a||:|
1ces sc| |ese/|| //cm |||s /ec|a/e.
ConcIusion
atabasc nginc supports rangc partitioning ol data and indiccs, which is cntircly
transparcnt to thc application. Rangc partitioning partitions rows bascd on thc valuc ol
thc partition kcy. !n othcr words, thc data is dividcd using thc valucs ol thc partition kcy.
Cha pt er 2 6: Opt i mi z i ng Tec hni ques f or 8us i nes s | nt el l i genc e 637
!l you want to partition your data, you must complctc thc lollowing stcps:

Crcatc partition lunction and partition schcmc
Crcatc partitioncd indiccs (il ncccssary)
Using dillcrcnt lilcgroups to scparatc tablc data, you achicvc bcttcr pcrlormancc,
highcr data availability, and casicr maintcnancc.
Thc partition lunction is uscd to map thc rows ol a tablc or indcx into partitions
bascd on thc valucs ol a spccilicd column. To crcatc a partition lunction, usc thc
CRAT PART!T!N FUNCT!N statcmcnt. To associatc a partition lunction
with spccilic lilcgroups, usc partition schcmc. Vhcn you partition tablc data, thc
indiccs that arc associatcd with that tablc can bc partitioncd, too. You can partition
tablc indiccs using thc cxisting partition schcma lor that tablc or a dillcrcnt onc.
Star schcma qucry optimization is an indcx bascd optimization tcchniquc, which
supports thc optimal usc ol indiccs on thc hugc lact tablcs. Thc main advantagcs ol this
tcchniquc arc thc lollowing:

sclcctivc star schcma qucrics

This chaptcr is thc last chaptcr ol thc book's part conccrning busincss intclligcncc.
Thc ncxt chaptcr starts thc last part ol thc book and givcs you an introduction to XML.
This page intentionally left blank
Part V
Icyond Iclatlonal Iata
Copyright 2008 by The McGraw-Hill Companies. Click here for terms of use.
This page intentionally left blank
In 7bis Cbapter
WorId Wide Web
XML-ReIated Languages
XML-asic Concepts
vcrvlcw ol XMI
Cbapter 27
Copyright 2008 by The McGraw-Hill Companies. Click here for terms of use.
642 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
T
his chaptcr introduccs thc xtcnsiblc Markup Languagc (XML), which has
bccomc morc and morc important as a data storagc lormat. Thc chaptcr
lirst dcscribcs thc Vorld Vidc Vcb. !t thcn introduccs thc cxisting markup
languagcs and thc position ol XML as a markup languagc. Thc chaptcr also cxplains
thc basic conccpts ol XML, such as clcmcnts, attributcs, and namcspaccs. Thc cnd ol
thc chaptcr discusscs thc documcnt typc dclinition (T) languagc and thc XML
Schcma languagc.
WorId Wide Web
Thc Vorld Vidc Vcb has bccn gaining cnormous importancc as a mcdium, bccausc it
is uscd lor many activitics. Thc Vcb compriscs ol thc most !ntcrnct scrviccs (undcr thc
samc uscr intcrlacc) and is thcrclorc thc most powcrlul !ntcrnct scrvicc ol all. Gcncrally,
thc Vcb has lour parts:
Vcb scrvcr
Vcb browscr
HTML (Hypcrtcxt Markup Languagc)
HTTP (Hypcrtcxt Translcr Protocol)
Thc wcb scrvcr scnds pagcs (usually HTML pagcs) to thc nctwork. A wcb browscr
rcccivcs thc pagcs and displays thcm on thc computcr scrccn. (Microsolt !ntcrnct
xplorcr is an cxamplc ol a wcb browscr.)
You usc HTML to crcatc documcnts lor thc Vcb. This languagc allows you to
lormat data that is shown using a wcb browscr. Thc simplicity ol HTML is onc ol
thc rcasons that thc Vcb has gaincd such importancc. Howcvcr, HTML has onc
main disadvantagc: it can tcll you only how thc data should look. !n othcr words, thc
languagc docs not allow you to gain any mcaning out ol thc data.
HTML documcnts arc tcxt lilcs that contain tags, and cach tag is writtcn in anglc
brackcts. Thc most important tags arc hypcrlinks. You usc hypcrlinks to rclcrcncc
documcnts that arc managcd by a wcb scrvcr. Thosc rclcrcnccs build thc nctwork that
spans thc wholc !ntcrnct. For this rcason, it is callcd thc "Vorld Vidc Vcb."
HTTP is a protocol that "connccts" a wcb browscr with a wcb scrvcr and scnds thc
availablc pagcs lrom thc lormcr to thc lattcr. !l thc pagcs contain anothcr hypcrlink, thc
protocol is uscd to conncct to that wcb scrvcr, using thc givcn addrcss.
Cha pt er 2 7: Ov er v i ew of XML 643
XML-ReIated Languages
XML is a languagc that is uscd lor thc digital rcprcscntation ol documcnts. This
languagc is rclatcd to two othcr languagcs:
SGML
HTML
Standard Gcncral Markup Languagc (SGML) is a vcry powcrlul markup languagc
that is uscd lor thc intcrchangc ol largc and complcx documcnts. (A markup languagc
spccilics spccial signs that arc uscd cithcr lor lormatting documcnts or to rcprcscnt thc
logical structurc ol documcnts. LaTX is an cxamplc ol a lormatting markup languagc.)
SGML is uscd in many arcas whcrc thcrc is a ncccssity lor complcx documcnts, such as
airplanc maintcnancc. As you will rcad in just a momcnt, XML is SGML litcthat is, it
is a simplilicd subsct ol SGML that is primarily uscd lor thc Vcb.
HTML is thc most important markup languagc uscd lor thc Vcb. ach HTML
documcnt is an SGML documcnt with a lixcd documcnt typc dclinition (T).
(Fixcd documcnt typcs arc dcscribcd in thc ncxt scction.) Thcrclorc, HTML is just an
instancc ol SGML.
HTML has two important lcaturcs:
!t is uscd only to lormat a documcnt.
!t is not an cxtcnsiblc languagc.
HTML is a markup languagc that you can usc to dcscribc how thc data should look.
(n thc othcr hand, this languagc ollcrs morc than a simplc lormattcd languagc such as
LaTX, bccausc its clcmcnts arc gcncralizcd and dcscriptivc.)
HTML only uscs a lixcd numbcr ol clcmcnts. For this rcason, you cannot usc HTML
suitably lor particular documcnt typcs.
XML-asic Concepts
XML is an HTMLlikc languagc that is uscd lor data cxchangc. !n contrast to
HTML, which has a lixcd numbcr ol tags and whcrc cach tag has its own mcaning, thc
rcpcrtoirc ol tags in XML is not sct in advancc, and scmantic mcaning is not sct lor any
XML tag.
644 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
xamplc 27.1 hclps to clarily thcsc and othcr propcrtics ol XML. 8ut bclorc you
look at thc dillcrcnt parts ol an XML documcnt, considcr thc rcquircmcnts ol a
wclllormcd XML documcnt:
!t has a root clcmcnt.
vcry opcning tag is lollowcd by a matching closing tag.

An attributc must havc a valuc, which is quotcd.
XAMPL 27.1
:xml vcrsion-"1.0" cncoding-"UTF8":~
PcrsonList Typc-"mploycc"~
Titlc~ \aluc-"mploycc List"~/Titlc~
Contcnts~
mploycc~
Namc~Ann Joncs/Namc~
No~10102/No~
cptno~d3/cptno~
Addrcss~
City~allas/City~
Strcct~Main St/Strcct~
/Addrcss~
/mploycc~
mploycc~
Namc~John 8arrimorc/Namc~
No~18316/No~
cptno~d1/cptno~
Addrcss~
City~Scattlc/City~
Strcct~Abbcy Rd/Strcct~
/Addrcss~
/mploycc~
/Contcnts~
/PcrsonList~
Cha pt er 2 7: Ov er v i ew of XML 645
An XML documcnt, as shown in xamplc 27.1, contains gcncrally thrcc parts:

vcrsion ol XML it is dcaling with (vcrsion 1.0 in xamplc 27.1)
An optional schcma (usually writtcn using T or XS, scc thc scction
A root clcmcntthc clcmcnt that contains all othcr clcmcnts
You usc XML to digitally rcprcscnt documcnts. To rcprcscnt a documcnt, you havc
to know its structurc. For instancc, il you considcr a book as a documcnt, it can lirst bc
brokcn into chaptcrs (with titlcs). ach chaptcr compriscs scvcral scctions (with thcir
titlcs and corrcsponding ligurcs), and cach scction has onc or morc paragraphs.
All parts ol an XML documcnt that bclong to its logical structurc arc callcd
elements. Thcrclorc, in XML, cach clcmcnt rcprcscnts a componcnt ol a documcnt. !n
xamplc 27.1, PersonList, Title, and Contents arc cxamplcs ol XML clcmcnts. Also,
cach clcmcnt can contain othcr clcmcnts. (Thc parts ol an clcmcnt that do not bclong
to thc logical structurc ol a documcnt arc callcd charactcr data. For instancc, words or
scntcnccs in a book can bc trcatcd as charactcr data.)
All clcmcnts ol a documcnt build a hicrarchy ol clcmcnts that is callcd thc trcc
structurc ol thc documcnt. ach structurc has an clcmcnt on thc top lcvcl that contains
all othcr clcmcnts. This clcmcnt is callcd thc root clcmcnt. All clcmcnts that do not
contain any subclcmcnts arc callcd lcavcs.
|s :cs|/cs| |c |/|, a|e/e |c||1 |cs c/e 1e|e/m|se1 |, ||e |csace s(e:|/|:c||cs, |c scmes |s //| c/e
:|cses |, ||e (/c/cmme/.
Thc XML clcmcnts dircctly ncstcd within othcr clcmcnts arc callcd childrcn. For
instancc, in xamplc 27.1, Name, No, and Address arc childrcn ol Employee, which
is a child ol Contents, which is again a child ol thc root clcmcnt PersonList. (Thc
rclationships ancestor and descendant arc also dclincd in thc XML languagc.)
ach clcmcnt can havc cxtra inlormation that is attachcd to it. Such inlormation is
callcd an attribute, and it dcscribcs thc clcmcnt's propcrtics. Attributcs arc uscd togcthcr
with clcmcnts to rcprcscnt objccts (that is, documcnt typcs). !n thc tag
PcrsonList Typc-"mploycc"~
646 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Type is thc namc ol an attributc that bclongs to thc clcmcnt PersonList, and
Employee is thc attributc valuc. Thc lollowing scction dcscribcs attributcs in dctail.
XML Attributes
Attributcs arc uscd to rcprcscnt data. n thc othcr hand, clcmcnts can also bc uscd lor
thc samc purposc. For this rcason, it is plausiblc to ask whcthcr wc nccd attributcs at all,
bccausc almost cvcrything you can do using attributcs is possiblc to do with clcmcnts
(and subclcmcnts). Howcvcr, thc lollowing tasks can bc accomplishcd only with
attributcs:

nlorcc a limitcd kind ol rclcrcntial constraint
|e/e |s sc ese/c| /a|e /c/ |ca ,ca s|ca|1 1e/|se 1c|c. |e |es| /a|e c/ ||am| |s |c ase cs c||/||a|e a|es c
(/c(e/|, c/ cs e|emes| |s ese/c|, cs1 |c ase sa|e|emes|s /c/ c s(e:|/|: (/c(e/|, c/ cs e|emes|.
An attributc can bc spccilicd to bc an ! typc attributc. Thc valuc ol thc !
attributc must bc uniquc within thc XML documcnt. Thcrclorc, thc ! attributc is
always uscd to dclinc a uniquc valuc.
An attributc ol typc !RF must rclcr to a valid ! dcclarcd in thc samc documcnt.
!n othcr words, thc valuc ol thc !RF attributc must occur in thc documcnt as a valuc
ol thc corrcsponding ! attributc.
An attributc ol typc !RFS spccilics a list ol strings, scparatcd by blanks, that arc
rclcrcnccd by thc valucs ol thc ! attributc. For instancc, thc lollowing linc shows thc
XML lragmcnt ol an !RFS attributc:
cpartmcnt Mcmbcrs-"10102 18316"/~
(This cxamplc assumcs that thc attributc No ol thc Employee clcmcnt is thc !
attributc, whilc thc attributc Members ol thc Department clcmcnt is ol thc typc
!RFS.)
Thc pairs !/!RF and !/!RFS corrcspond to primary kcy/lorcign kcy
rclationships in thc databasc, with a lcw dillcrcnccs. !n thc XML documcnt, thc valucs
ol dillcrcnt ! typc attributcs must bc distinct. For instancc, il you havc CustomerD
and SalesOrderD attributcs in an XML documcnt, thcsc valucs must bc distinct.
Cha pt er 2 7: Ov er v i ew of XML 647
|e |,(es mes||cse1 c|c|e (||, |||||, cs1 |||||: c/e (c/| c/ ||e 1c:ames| |,(e 1e/|s|||css (||s, 1|s:asse1
|c|e/ |s |||s :|c(|e/.
XML Namespaces
Vhcn using XML, you build a vocabulary ol tcrms that is appropriatc lor thc domain
in which you modcl your data. !n this situation, dillcrcnt vocabularics lor dillcrcnt
domains can causc naming conllicts whcn you want to mix thc domains togcthcr in
an XML documcnt. (This is usually thc casc whcn you want to intcgratc inlormation
obtaincd lrom dillcrcnt domains.) This problcm can bc solvcd using XML namcspaccs.
Gcncrally, thc namc ol cvcry XML tag must bc writtcn in thc lorm namespacename,
whcrc namespace spccilics an XML namcspacc and name is an XML tag.
A namcspacc is always rcprcscntcd by a worldwidc uniquc UR! (uniform resource
identif ier), which is usually a URL but can bc an abstract idcntilicr, too.
xamplc 27.2 shows thc usc ol two namcspaccs.
XAMPL 27.2
Faculty xmlns-"http://www.lhroscnhcim.dc/inlormatik"
xmlns:lib-"http:// www.lhroscnhcim.dc/library"~
Namc~8ook/Namc~
Fcaturc~
lib:Titlc~!ntroduction to atabasc Systcms/lib:Titlc~
lib:Author~A. Finkclstcin/lib:Author~
/Fcaturc~
/Faculty~
Namcspaccs arc dclincd using thc xmlns attributc. xamplc 27.2 spccilics two
namcspaccs. Thc lirst onc is thc default namespace, bccausc it is spccilicd only with
thc xmlns kcyword. This namcspacc is thc shorthand lor thc namcspacc http://
www.lhroscnhcim.dc/inlormatik. Thc sccond namcspacc is spccilicd in thc lorm
xmlnslib. Thc prclix lib scrvcs as thc shorthand lor http://www.lhroscnhcim.dc/library.
Tags bclonging to thc lattcr namcspacc should bc prclixcd with lib Tags without
any prclix bclong to thc dclault namcspacc. (!n xamplc 27.2, two tags bclong to thc
sccond namcspacc: Title and Author.)
648 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
!n contrast to HTML, which contains a sct ol lixcd rulcs that you must lollow whcn
you crcatc an HTML documcnt, XML docs not havc such rulcs, bccausc this languagc
is intcndcd lor many dillcrcnt application arcas. Hcncc, XML includcs a languagc that
is uscd to spccily thc documcnt structurc.
A sct ol rulcs lor structuring an XML documcnt is callcd a documcnt typc dclinition
(T). A T can bc spccilicd as a part ol thc XML documcnt, or thc XML
documcnt can contain a unilorm rcsourcc locator (URL) indicating whcrc thc T is
storcd. A documcnt that conlorms to thc associatcd T is callcd a valid documcnt.
//| 1ces sc| /ea|/e ||c| 1c:ames|s |c|e :c//es(cs1|s ||s, |a| || /ea|/es ||c| 1c:ames|s |e ae|| /c/me1.

xamplc 27.3 shows thc T lor thc XML documcnt in xamplc 27.1.
XAMPL 27.3
:xml vcrsion-"1.0" cncoding-"UTF8":~
!CTYP PcrsonList SYSTM "C:\tmp\Unbcnannt4.dtd"~
!LMNT mployccList (Titlc, Contcnts)~
!LMNT Titlc MPTY~
!LMNT Contcnts (mploycc)~
!LMNT mploycc (Namc, No, cptno, Addrcss)~
!LMNT Namc (Fnamc, Lnamc)~
!LMNT Fnamc (#PCATA)~
!LMNT Lnamc (#PCATA)~
!LMNT No (#PCATA)~
!LMNT cptno (#PCATA)~
!LMNT Addrcss (City, Strcct) ~
!LMNT City (#PCATA)~
!LMNT Strcct (#PCATA)~
!ATTL!ST mployccList Typc CATA #!MPL!
atc CATA #!MPL!~
!ATTL!ST Titlc \aluc CATA #RQU!R~
Thcrc arc scvcral common T componcnts: a namc (EmployeeList in xamplc 27.3)
and a sct ol LMNT and ATTL!ST statcmcnts. Thc namc ol a T must conlorm to
Cha pt er 2 7: Ov er v i ew of XML 649
thc tag namc ol thc root clcmcnt ol thc XML documcnt (scc xamplc 27.1) that uscs thc
T lor validation.
lcmcnt typc dcclarations must start with thc LMNT statcmcnt, lollowcd by
thc namc ol thc clcmcnt typc bcing dclincd. (vcry clcmcnt in a valid XML documcnt
must conlorm to an clcmcnt typc dcclarcd in thc T.) !n xamplc 27.3, thc lirst
LMNT statcmcnt spccilics that thc clcmcnt EmployeeList consists ol Title and
Contents clcmcnts, in that ordcr. Thc Title clcmcnt docs not contain any subclcmcnts.
Thc sign in thc dclinition ol thc Contents clcmcnt indicatcs that thcrc arc zcro
or morc clcmcnts ol thc Employee typc. Thc clcmcnts Iname, Lname, No, Deptno,
City, and Street arc dcclarcd to bc alphanumcricalthat is, ol typc #PCATA.
||emes|s :cs |c|1 s|m(|e c/ :cm(|es |,(es. |s |scm(|e 1/.?, 444tess /e(/eses|s c :cm(|es |,(e cs1 C/t,
c s|m(|e |,(e.
Attributcs arc dcclarcd lor spccilic clcmcnt typcs using thc ATTL!ST statcmcnt.
This mcans that cach attributc dcclaration starts with thc string !ATTL!ST.
!mmcdiatcly altcr that comcs thc attributc's namc and its data typc. !n xamplc 27.3,
thc EmployeeList clcmcnt is allowcd to havc thc attributcs Type and Date, whilc
thc Title clcmcnt can only havc thc Value attributc. (All othcr clcmcnts do not havc
attributcs.)
Thc #!MPL! kcyword spccilics that thc corrcsponding attributc is optional,
whilc thc #RQU!R kcyword dctcrmincs thc mandatory lorm ol thc attributc.
/||/||a|es :cs |c|1 cs|, s|m(|e 1c|c |,(es.

8csidcs thc dclinition ol a documcnt's structurc, lormatting a documcnt can bc an
important issuc lor thosc ol you who do not want thc wcb browscr, such as Microsolt
!ntcrnct xplorcr, to control thc lorm ol thc documcnt. For this task, XML supports
anothcr languagc callcd xtcnsiblc Stylcshcct Languagc (XSL), which allows you to
dcscribc how thc data ol your documcnt should bc lormattcd or displaycd.
|e s|,|e c/ c 1c:ames| |s 1es:/||e1 cs c se(c/c|e as||. |c/ |||s /ecscs, ec:| 1c:ames| a|||ca| |||s c11|||csc|
as|| a||| ase ||e 1e/ca|| /c/mc|||s c/ ||e ae| |/case/.
650 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
XML Scbema
XML Schcma, or XML Schcma clinition languagc (XS), is a L lor XML
documcnts. !t dclincs a standard sct ol basc typcs that arc supportcd as typcs in XML.
XML Schcma contains many advanccd lcaturcs and is thcrclorc signilicantly morc
complcx than thc Ts.
//| ::|emc |s 1|s:asse1 cs|, |/|e/|, |s |||s |cc| |e:case c/ ||s :cm(|es||,. (:ee c|sc t|c(|e/ 1? /c/ c 1|s:ass|cs
c/ //| ::|emc sa((c/| |s :9| :e/|e/.
Thc main lcaturcs ol XML Schcma arc thc lollowing:
!t uscs thc samc syntax as that uscd lor XML documcnts. (For this rcason,
schcmas arc thcmsclvcs wclllormcd XML documcnts.)
!t is intcgratcd with thc namcspacc mcchanism. (Although thcrc can bc morc
!t providcs a sct ol basc typcs, thc samc way SQL providcs CHAR, !NTGR,
and othcr standard data typcs.
!t supports primary/lorcign kcy intcgrity constraints.
ConcIusion
XML is a data rcprcscntation lormat bascd on SGML, and it is uscd morc and morc
as a data storagc lormat. An XML documcnt contains scvcral tags that arc choscn by
thc pcrson who implcmcnts thc documcnt. All parts ol an XML documcnt that bclong
to its logical structurc arc callcd clcmcnts. lcmcnts can hold simplc or complcx data
typcs. ach clcmcnt can havc cxtra inlormation that is attachcd to it. Such inlormation
is callcd an attributc. Attributcs can hold only simplc data typcs.
A T is a sct ol rulcs that structurc an XML documcnt. An XML documcnt that
conlorms to thc associatcd T is callcd a valid documcnt. !nstcad ol Ts, you can
usc XS to validatc an XML documcnt. XS compriscs data dclinition statcmcnts lor
XML, in much thc samc way that thc L (scc Chaptcr 1), contains data dclinition
statcmcnts lor SQL.
Thc ncxt chaptcr discusscs XML in rclation to thc SQL Scrvcr systcm.
In 7bis Cbapter
Metbods of Storing XML
Documents in ReIationaI
Databases
Storing XML Documents in
SL Server
Retrieving Stored XML
Documents and Fragments
Presenting ReIationaI Data
as XML Documents
SL Server Xuery Metbods
SQI Scrvcr and XMI
Cbapter 28
Copyright 2008 by The McGraw-Hill Companies. Click here for terms of use.
652 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
T
his chaptcr discusscs in dctail thrcc gcncral topics that arc important whcn
XML and rclational databasc systcms arc put togcthcr:
Storing XML documcnts in rclational databascs
Rctricving storcd XML documcnts
Prcscnting rclational data in XML lorm
Thc lirst part ol thc chaptcr discusscs thc dillcrcnt ways in which XML documcnts
can bc storcd in rclational databascs. Thc most important storagc lorm, using thc XML
data typc, is introduccd altcr that. Thc rctricval ol storcd XML documcnts using systcm
storcd proccdurcs and thc standard !NSRT statcmcnt is shown in thc ncxt part ol
thc chaptcr. Thc othcr problcm, thc prcscntation ol rclational data in XML, is shown
too. Thc cnd ol thc chaptcr briclly cxplains thc XQucry languagc and thc cxisting SQL
Scrvcr XQucry mcthods.
|s |||s :|c(|e/, //| |cs |ac mecs|ss. ||/s|, |||s |e/m s(e:|/|es ||e |csace, |s|es1e1 /c/|a( |csace.
:e:cs1, ||e scme |e/m |s ase1 |c s(e:|/, ||e //| 1c|c |,(e |s :9| :e/|e/. c |ee( ||e 1|s||s:||cs :| ec/, |||s
:|c(|e/ ases ||e |e/m //| |c s(e:|/, ||e |csace cs1 ases ||e (|/cse //| 1c|c |,(e |c s(e:|/, ||e 1c|c
|,(e. (/|sc, //| :c|ams mecss c :c|ams c/ ||e //| 1c|c |,(e.
Metbods of Storing XML Documents
in ReIationaI Databases
As you alrcady know lrom Chaptcr 1, thc rclational data modcl is thc bcst modcl to
usc il you havc structurcd data with thc corrcsponding schcma. n thc othcr hand, il
thc data you usc is scmistructurcd, you havc to know how to modcl thc data. !n that
casc, XML is a good choicc, bccausc it is a platlormindcpcndcnt modcl, which cnsurcs
portability ol scmistructurcd data.
A tight rclationship cxists bctwccn rclational databasc systcms and XML documcnts,
bccausc thc goal ol modcrn databasc systcms is to storc any kind ol data. Thcrc arc
thrcc gcncral tcchniqucs lor storing XML documcnts in rclational databascs:
As "raw" documcnts
ccomposcd into rclational columns
Using nativc storagc
Cha pt er 2 8: S QL S er ver a nd XML 653
!l you storc an XML documcnt as a largc objcct (L8), an cxact copy ol thc data is
storcd. !n this casc, XML documcnts arc storcd "raw"that is, in thcir charactcr string
lorm. Thc raw lorm allows you to inscrt documcnts vcry casily. Thc rctricval ol such a
documcnt is vcry cllicicnt il you rctricvc thc cntirc documcnt.
To dccomposc an XML documcnt into scparatc columns ol onc or morc tablcs, you
can usc annotatcd XS. (Thc XML Schcma clinition languagc, dcscribcd briclly in
thc prcvious chaptcr, dclincs a sct ol standard data typcs that arc supportcd in XML
documcnts.) !n this casc, thc hicrarchical structurc ol thc documcnt is prcscrvcd, whilc
ordcr among clcmcnts is ignorcd. (As you alrcady know, thc rclational modcl docs not
support ordcring ol columns in a tablc, whcrcas clcmcnts ol an XML documcnts arc
ordcrcd.) Storing XML documcnts in dccomposcd lorm makcs it much casicr to indcx
an clcmcnt il it is placcd in its own column.
|e 1e:cm(cs|||cs (/c:ess c/ cs //| 1c:ames| |s|c se(c/c|e :c|amss |s c|sc |scas cs s|/e11|s.

Nati.e storage mcans that XML documcnts arc storcd in thcir parscd lorm. !n othcr
words, thc documcnt is storcd in an intcrnal rcprcscntation (!nlosct, lor instancc) that
prcscrvcs thc XML contcnt ol thc data. (!nlosct, or XML Information Set, is a Vorld
Vidc Vcb Consortium |V3C, www.w3.org| spccilication that providcs a sct lor usc in
othcr spccilications that nccd to rclcr to thc inlormation in an XML documcnt.)
Using nativc storagc makcs it casy to qucry inlormation bascd on thc structurc
ol thc XML documcnt. n thc othcr hand, rcconstructing thc original lorm ol thc
XML documcnt is dillicult, bccausc thc crcatcd contcnt may not bc an cxact copy ol
thc documcnt. (Thc dctailcd inlormation about thc signilicant whitc spaccs, ordcr ol
attributcs, and namcspacc prclixcs in XML documcnts is gcncrally not rctaincd.)
Vith this gcncral introduction ol storagc modcls in mind, thc lollowing scction
dcscribcs how SQL Scrvcr supports thcsc tcchniqucs.
Storing XML Documents in SL Server
SQL Scrvcr supports all thrcc gcncral tcchniqucs lor storing XML documcnts discusscd
in thc prcvious scction:
Raw documents SQL Scrvcr uscs thc \ARCHAR(MAX) and
\AR8!NARY(MAX) data typcs to storc XML documcnts as raw documcnts.
654 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
|e |m(|emes|c||cs c/ //| |s :9| :e/|e/ (:c||e1 :9|//| |s sc| (c/| c/ :9| :e/|e/ 1^^?. :9|//| |s c//e/e1 |,
/|:/csc/| cs c se(c/c|e (/c1a:|.
Decomposition SQL Scrvcr can dccomposc XML documcnts into scparatc
columns ol tablcs by using thc sp_xml_preparedocument systcm proccdurc.
output trcc can thcn bc storcd in columns ol rclational tablcs using thc standard
!NSRT statcmcnt and thc pcnXML lunction.)
Native storage
nativc way in a databasc managcd by atabasc nginc. (atabasc systcms, such
as atabasc nginc, that storc XML documcnts in a complctcly parscd lorm arc
callcd nativc XML databasc systcms.)
Thc lollowing scctions discuss in dctail thc last two tcchniqucs. 8ccausc thc usc ol
thc XML data typc is thc most important storagc lorm, it is discusscd lirst.
Storing XML Documents Using tbe XML Data 7ype
Thc XML data typc is thc basc data typc in TransactSQL, mcaning you can usc thc
XML data typc in thc samc way you usc thc standard data typcs, such as !NTGR
or CHARACTR. n thc othcr hand, thc XML data typc has somc limitations,
bccausc an XML column cannot bc dcclarcd using thc UN!QU, PR!MARY KY, or
FR!GN KY clauscs.
Gcncrally, you can usc thc XML data typc to dcclarc thc lollowing:
Tablc columns
\ariablcs

|e /c||ca|s |es| 1es:/||es ||e ase c/ ||e //| 1c|c |,(e |c 1e:|c/e c |c||e :c|ams. |e ase c/ |||s |,(e |c
1e:|c/e |c/|c||es c/ (c/cme|e/s |s s|m||c/.
xamplc 28.1 shows thc usc ol thc XML data typc to dcclarc a column ol a tablc.
Cha pt er 2 8: S QL S er ver a nd XML 655
XAMPL 28.1
US samplc,
CRAT TA8L xmltab (id !NTGR NT NULL PR!MARY KY,
xml_column XML),
Thc CRAT TA8L statcmcnt in xamplc 28.1 crcatcs a tablc with two columns:
id and xml_column. Thc id column is uscd to idcntily uniqucly cach row ol thc tablc.
xml_column is an XML column that will bc uscd in thc lollowing cxamplcs to show
how XML documcnts can bc storcd, indcxcd, and rctricvcd.
As prcviously statcd, XML documcnts can bc storcd in a nativc way in a column ol
thc XML data typc. xamplc 28.2 shows thc usc ol thc !NSRT statcmcnt to storc
such a documcnt.
XAMPL 28.2
US samplc,
!NSRT !NT xmltab \ALUS (1,
':xml vcrsion-"1.0":~
PcrsonList Typc-"mploycc"~
Titlc~ \aluc-"mploycc List"~/Titlc~
Contcnts~
mploycc~
Namc~Ann Joncs/Namc~
No~10102/No~
cptno~d3/cptno~
Addrcss~
City~allas/City~
Strcct~Main St/Strcct~
/Addrcss~
/mploycc~
mploycc~
Namc~John 8arrimorc/Namc~
No~18316/No~
cptno~d1/cptno~
Addrcss~
City~Scattlc/City~
Strcct~Abbcy Rd/Strcct~
/Addrcss~
/mploycc~
/Contcnts~
/PcrsonList~'),
656 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Thc !NSRT statcmcnt in xamplc 28.2 inscrts two valucs: thc valuc ol thc idcntilicr
and an XML documcnt. (Thc inscrtcd XML documcnt is thc samc documcnt uscd in
thc prcvious chaptcr, scc xamplc 27.1.) 8clorc thc XML documcnt is storcd, it will
bc parscd using thc XML parscr, which chccks its syntax. Actually, thc parscr chccks
whcthcr or not thc particular XML documcnt is wcll lormcd. For instancc, il you omit
thc last row ol thc XML documcnt (/PcrsonList~), thc XML parscr displays thc
lollowing crror mcssagc:
Msg 9400, Lcvcl 16, Statc 1, Linc 3
XML parsing: linc 24, charactcr 0, uncxpcctcd cnd ol input
!l you usc thc SLCT statcmcnt to scc thc contcnt ol thc xmltab tablc, SQL Scrvcr
Managcmcnt Studio uscs thc XML cditor to display XML documcnts. (To display thc
cntirc documcnt in thc cditor, click thc corrcsponding valuc in thc rcsult sct.)
Indexing an XML CoIumn
atabasc nginc storcs XML valucs intcrnally as binary largc objccts. Vithout an indcx,
thcsc objccts arc dccomposcd at run timc to cvaluatc a qucry, which can bc timcconsuming.
Thcrclorc, thc rcason lor indcxing XML columns is to improvc qucry pcrlormancc.
|/ ,ca acs| |c :/ec|e cs, ||s1 c/ //| |s1|:es, ||e :c//es(cs1|s |c||e mas| |s:|a1e ||e es(||:|| 1e/|s|||cs c/ ||e
(/|mc/, |e,.
Thc systcm supports a primary XML indcx and thrcc typcs ol sccondary XML
indiccs. Thc primary XML indcx indcxcs all tags, valucs, and paths within thc XML
instanccs ol an XML column. Qucrics usc thc primary XML indcx to rcturn scalar
valucs or XML subtrccs.
xamplc 28.3 crcatcs a primary XML indcx.
XAMPL 28.3
US samplc,
G
CRAT PR!MARY XML !NX i_xmlcolumn N xmltab(xml_column),
As you can scc lrom xamplc 28.3, thc crcation ol a primary XML indcx is similar
to thc crcation ol a "normal" indcx dcscribcd in Chaptcr 10. A primary XML indcx uscs
an XML instancc to gcncratc thc corrcsponding rclational intcrnal lorm out ol it. That
way, thc rcpcatcd runtimc gcncration ol thc intcrnal lorm lor qucrics and updatcs is
omittcd.
Cha pt er 2 8: S QL S er ver a nd XML 657
To lurthcr improvc scarch pcrlormancc, you can crcatc sccondary XML indiccs. A
primary XML indcx must cxist bclorc sccondary indiccs can bc built. You can crcatc
thrcc typcs ol XML sccondary indiccs using dillcrcnt kcywords:
IOR PATH Crcatcs a sccondary XML indcx ovcr thc documcnt structurc
IOR VALUE Crcatcs a sccondary XML indcx ovcr thc clcmcnt and attributc
valucs ol thc XML column
IOR PROPERTY Crcatcs a sccondary XML indcx that scarchcs lor a propcrty
Thc lollowing list givcs you somc guidclincs lor crcating sccondary XML indiccs:

mcthod on XML columns in thc VHR clausc ol thc TransactSQL languagc.
!l your qucrics rctricvc multiplc valucs lrom individual XML instanccs by using
path cxprcssions, thc usc ol thc PRPRTY indcx may bc hclplul.
!l your qucrics involvc rctricval ol valucs within XML instanccs without knowing
thc clcmcnt or attributc namcs that contain thosc valucs, you may want to crcatc
thc \ALU indcx.
xamplc 28.4 shows thc usc ol thc FR PATH kcyword. (Thc syntax lor crcating
all othcr sccondary XML indiccs is analogous.)
XAMPL 28.4
US samplc,
G
CRAT XML !NX i_xmlcolumn_path N xmltab(xml_column)
US!NG XML !NX i_xmlcolumn FR PATH,
xamplc 28.4 shows thc crcation ol thc sccondary XML indcx with thc FR PATH
kcyword. You must spccily thc US!NG clausc il you want to dclinc any sccondary
XML indcx.
XML indiccs havc somc limitations in rclation to "normal" indiccs:
XML indiccs cannot bc compositc indiccs.

658 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
|e /ecscs /c/ :/ec||s //| |s1|:es |s 1|//e/es| //cm ||e /ecscs /c/ :/ec||s :cs|es|es| |s1|:es. //| |s1|:es
es|cs:e ||e (e//c/mcs:e c/ /9ae/, ae/|es, a|||e :cs|es|es| |s1|:es es|cs:e ||e (e//c/mcs:e c/ :9| ae/|es.
SQL Scrvcr also supports thc corrcsponding ALTR !NX and RP !NX
statcmcnts. Thc ALTR !NX statcmcnt allows you to changc thc structurc ol an
cxisting XML indcx, whilc thc RP !NX statcmcnt dclctcs such an indcx.
Thcrc is also a catalog vicw lor XML indiccs, callcd sys.xml_indexes. This vicw
rcturns onc row pcr cach XML indcx. Thc most important columns ol thc vicw arc
using_xml_index_id and secondary_type. Thc lormcr spccilics whcthcr thc indcx is
primary or sccondary, whilc thc lattcr dctcrmincs thc typc ol thc sccondary indcx ("P"
lor PATH, "\" lor \ALU, and "R" lor PRPRTY sccondary indcx). (8csidcs that,
this vicw inhcrits columns lrom thc sys.indexes catalog vicw.)
7yped vs. Untyped XML
As you alrcady know lrom Chaptcr 27, an XML documcnt can bc wcll lormcd and
valid. (nly a wclllormcd documcnt can bc validatcd.) An XML documcnt that
conlorms to onc or morc givcn schcmas is said to bc schema .alid and is callcd an
instance document ol thc schcmas. Thc XML schcmas arc uscd to pcrlorm morc prccisc
typc chccks during compilation ol qucrics.
XML data typc columns, variablcs, and paramctcrs may bc typcd (conlorm to a sct ol
schcmas) or untypcd. !n othcr words, whcncvcr a typcd XML instancc is assigncd to an
XML column data typc, variablc, or paramctcr, thc systcm validatcs thc instancc.
Thc lollowing scction cxplains thc usc ol XML schcmas, altcr which typcd XML
instanccs arc discusscd in morc dctail.
XML Scbemas and SL Server An XML schcma spccilics a sct ol data typcs that
cxist in a particular namcspacc. XML Schcma (or XML Schcma clinition Languagc)
is a data dclinition languagc lor XML documcnts.
SQL Scrvcr uscs thc CRAT XML SCHMA CLLCT!N statcmcnt to
import thc schcma componcnts into thc databasc. xamplc 28.5 shows thc usc ol this
statcmcnt.
XAMPL 28.5
US samplc,
CRAT XML SCHMA CLLCT!N mployccSchcma AS
N':xml vcrsion-"1.0" cncoding-"UTF16":~
xsd:schcma clcmcntFormclault-"unqualilicd"
Cha pt er 2 8: S QL S er ver a nd XML 659
attributcFormclault-"unqualilicd"
xmlns:xsd-"http://www.w3.org/2001/XMLSchcma" ~
xsd:clcmcnt namc-"cmployccs"~
xsd:complcxTypc mixcd-"lalsc"~
xsd:scqucncc~
xsd:clcmcnt namc-"lnamc" typc-"xsd:string"/~
xsd:clcmcnt namc-"lnamc" typc-"xsd:string"/~
xsd:clcmcnt namc-"dcpartmcnt" typc-"xsd:string"/~
xsd:clcmcnt namc-"salary" typc-"xsd:intcgcr"/~
xsd:clcmcnt namc-"commcnts" typc-"xsd:string"/~
/xsd:scqucncc~
/xsd:complcxTypc~
/xsd:clcmcnt~
/xsd:schcma~',
xamplc 28.5 shows how thc CRAT XML SCHMA CLLCT!N
statcmcnt can bc uscd to catalog thc EmployeeSchema schcma as a databasc objcct.
Thc XML schcma lor xamplc 28.5 includcs attributcs (clcmcnts) lor cmployccs, such
as lamily namc, last namc, and salary. (A dctailcd discussion ol XML schcmas is outsidc
thc scopc ol this introductory book.)
Gcncrally, an XML schcma collcction has a namc, which can bc qualilicd using thc
rclational schcma namc (dbo.EmployeeSchema, lor instancc). Thc schcma collcction
consists ol onc or morc schcmas that dclinc thc typcs in onc or morc XML namcspaccs.
!l thc targetNamespace attributc is omittcd lrom an XML schcma, that schcma docs
not havc an associatcd namcspacc. (Thcrc is a maximum ol onc such schcma insidc an
XML schcma collcction.)
SQL Scrvcr also supports thc ALTR XML SCHMA CLLCT!N and
RP XML SCHMA CLLCT!N statcmcnts. Thc lormcr allows you to add
ncw schcmas to an cxisting XML schcma collcction, whilc thc lattcr dclctcs an cntirc
schcma collcction.
7yped XML CoIumns, VariabIes, and Parameters ach typcd XML column,
variablc, or paramctcr must bc spccilicd with associatcd schcmas. To do this, thc namc
ol thc schcma collcction, which is crcatcd using thc CRAT XML SCHMA
CLLCT!N statcmcnt, must bc writtcn insidc thc pair ol parcnthcscs, altcr thc
instancc namc. xamplc 28.6 shows this.
XAMPL 28.6
US samplc,
CRAT TA8L xml_pcrsontab (id !NTGR,
xml_pcrson XML(mployccSchcma)),
660 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
Thc xml_person column in xamplc 28.6 is associatcd with thc XML schcma
collcction EmployeeSchema (scc xamplc 28.5). This mcans that all spccilications lrom
dclincd schcmas arc uscd to chcck whcthcr thc contcnt ol thc xml_person column is
valid. !n othcr words, whcn you inscrt a ncw valuc in thc typcd XML column (or modily
an cxisting valuc), all constraints spccilicd in thc schcmas arc chcckcd.
Thc spccilication ol an XML schcma collcction lor thc typcd XML instancc can bc
cxtcndcd with two kcywords:
CUMNT
CNTNT
Thc CUMNT kcyword spccilics that thc XML column can contain only
XML documcnts, whilc thc CNTNT kcyword, thc dclault valuc, spccilics that
thc XML column can contain cithcr documcnts or lragmcnts. (Rcmcmbcr, an XML
documcnt must havc a singlc root clcmcnt.)
xamplc 28.7 shows thc usc ol thc CUMNT kcyword.
XAMPL 28.7
US samplc,
CRAT TA8L xml_pcrsontab_doc (id !NTGR,
xml_pcrson XML(CUMNT mployccSchcma)),
XML Scbema CataIog Views SQL Scrvcr supports scvcral catalog vicws in rclation
to XML Schcma, thc most important ol which arc thc lollowing:
sys.xml_schema_attributes Rcturns a row pcr XML schcma componcnt that is
an attributc
sys.xml_schema_elements Rcturns a row pcr XML schcma componcnt that is
an clcmcnt
sys.xml_schema_components Rcturns a row pcr componcnt ol an XML
schcma
Storing XML Documents Using Decomposition
Thc sp_xml_preparedocument systcm proccdurc rcads thc XML tcxt providcd as
input, parscs thc tcxt, and rcprcscnts thc parscd documcnt as a trcc with thc various
nodcs: clcmcnts, attributcs, tcxt, and commcnts.
xamplc 28.8 shows thc usc ol thc sp_xml_preparedocument systcm proccdurc.
Cha pt er 2 8: S QL S er ver a nd XML 661
XAMPL 28.8
US samplc,
CLAR Chdoc int
CLAR Cdoc varchar(1000)
ST Cdoc -'RT~
mploycc~
Namc~Ann Joncs/Namc~
No~10102/No~
cptno~d3/cptno~
Addrcss~allas/Addrcss~
/mploycc~
mploycc~
Namc~John 8arrimorc/Namc~
No~18316/No~
cptno~d1/cptno~
Addrcss~Scattlc/Addrcss~
/mploycc~
/RT~'
XC sp_xml_prcparcdocumcnt Chdoc UTPUT, Cdoc
Thc XML documcnt in xamplc 28.8 is storcd as a string in thc doc variablc.
This string is shrcddcd by thc sp_xml_preparedocument systcm proccdurc. Thc
proccdurc rcturns a handlc (hdoc) that can thcn bc uscd to acccss thc ncwly crcatcd
rcprcscntation ol thc XML documcnt.
Thc sp_xml_removedocument systcm proccdurc rcmovcs thc intcrnal rcprcscntation
ol thc XML documcnt spccilicd by thc documcnt handlc and invalidatcs thc documcnt
handlc.
Thc ncxt scction shows how you can rctricvc thc storcd XML data in thc rclational
lorm.
Retrieving Stored XML Documents
and Fragments
You can gcncratc a sct ol rows lrom XML documcnts and lragmcnts, and qucry it by
using thc TransactSQL languagc. This is donc using pcnXML, which lcts you usc
TransactSQL statcmcnts to cxtract data lrom an XML documcnt. Using pcnXML,
you can rctricvc thc data lrom an XML documcnt as il it wcrc in a rclational tablc.
(pcnXML is an intcrnational standard lor documcnts that can bc lrccly implcmcntcd
by multiplc applications on multiplc platlorms.)
662 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
xamplc 28.9 shows how you can qucry thc XML documcnt lrom xamplc 28.8
using pcnXML.
|e :c1e |s |scm(|e 1?.^ mas| |e c((es1e1 |c ||e :c1e |s |scm(|e 1?.? cs1 ese:a|e1 |ce||e/.

XAMPL 28.9
SLCT FRM PNXML (Chdoc, '/RT/mploycc', 1)
V!TH (namc \ARCHAR(20) 'Namc',
no !NT 'No',
dcptno \ARCHAR(6) 'cptno',
addrcss \ARCHAR(50) 'Addrcss'),
Thc rcsult is
Name ae 6eptae a66ress
|aa Ieae. z a1 |+||+.
Ie|a |+rr|mere 1 a :e+tt|e
Presenting ReIationaI Data as XML Documents
As you alrcady know lrom Chaptcr 6, a SLCT statcmcnt qucrics onc or morc tablcs
and displays thc corrcsponding rcsult sct. Thc rcsult sct is displaycd by dclault as a tablc.
!l you want to display thc rcsult sct ol a qucry as an XML documcnt or lragmcnt, you
can usc thc FR XML clausc in your SLCT statcmcnt. Vith this clausc, you can
spccily onc ol thc lour lollowing modcs:
RAV
AUT
XPL!C!T
PATH
|e |0| //| :|case mas| |e s(e:|/|e1 c| ||e es1 c/ ||e :|||t s|c|emes|.
Cha pt er 2 8: S QL S er ver a nd XML 663
Thc lollowing scctions dcscribc cach ol thcsc modcs.
RAW Mode
Thc FR XML RAV option translorms cach row ol thc rcsult sct into an XML
clcmcnt with thc idcntilicr row~. ach column valuc is mappcd to an attributc ol thc
XML clcmcnt in which thc attributc namc is thc samc as thc column namc. (This is
truc only lor thc nonnull columns.)
xamplc 28.10 shows thc usc ol thc FR XML RAV option spccilicd lor thc join
ol thc employee and works_on tablcs lrom thc sample databasc.
XAMPL 28.10
US samplc,
SLCT cmploycc.cmp_no, cmp_lnamc, works_on.job
FRM cmploycc, works_on
VHR cmploycc.cmp_no - 10000
AN cmploycc.cmp_no - works_on.cmp_no
FR XML RAV,
xamplc 28.10 displays thc lollowing XML documcnt lragmcnt:
row cmp_no-"2581" cmp_lnamc-"Hanscl " job-"Analyst " /~
row cmp_no-"9031" cmp_lnamc-"8crtoni " job-"Managcr " /~
row cmp_no-"9031" cmp_lnamc-"8crtoni " job-"Clcrk " /~
Vithout thc FR XML RAV option, thc SLCT statcmcnt in xamplc 28.10
would rctricvc thc lollowing rows:
emp_ae emp_|aame [eh
z! |+a.e| |a+|.t
1 |ertea| M+a+er
1 |ertea| C|er|
As you can scc lrom both rcsults, thc lirst output produccs onc XML clcmcnt lor
cach row in thc rcsult sct.
664 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
AU7D Mode
AUT modc rcturns thc rcsult sct ol a qucry as a simplc, ncstcd XML trcc. ach tablc
in thc FRM clausc lrom which at lcast onc column appcars in thc SLCT list is
rcprcscntcd as an XML clcmcnt. Thc columns in thc SLCT list arc mappcd to thc
appropriatc clcmcnts' attributcs.
xamplc 28.11 shows thc usc ol AUT modc.
XAMPL 28.11
US samplc,
SLCT cmploycc.cmp_no, cmp_lnamc, works_on.job
FRM cmploycc, works_on
VHR cmploycc.cmp_no - 10000
AN cmploycc.cmp_no - works_on.cmp_no
FR XML AUT,
Thc rcsult is
cmploycc cmp_no-"9031" cmp_lnamc-"8crtoni "~
works_on job-"Managcr " /~
works_on job-"Clcrk " /~
/cmploycc~
cmploycc cmp_no-"2581" cmp_lnamc-"Hanscl "~
works_on job-"Analyst " /~
/cmploycc~
Thc rcsult in xamplc 28.11 is signilicantly dillcrcnt lrom thc rcsult in thc
prcvious cxamplc, although thc SLCT statcmcnt lor both cxamplcs is cquivalcnt
(cxccpt lor thc spccilication ol AUT modc instcad ol RAV modc). As you can scc
lrom xamplc 28.11, thc rcsult sct is displaycd as thc hicrarchy ol thc employee and
works_on tablcs. This hicrarchy is bascd on thc primary kcy/lorcign kcy rclationship
ol both tablcs. For this rcason, thc data lrom thc employee tablc is displaycd lirst, and
thc corrcsponding data lrom thc works_on tablc is displaycd altcr that, at thc lowcr
hicrarchy lcvcl.
Thc ncsting ol thc clcmcnts in thc rcsulting XML documcnt or lragmcnt is bascd
on thc ordcr ol tablcs idcntilicd by thc columns spccilicd in thc SLCT clausc,
thcrclorc, thc ordcr in which column namcs arc spccilicd in thc SLCT clausc is
signilicant. For this rcason, in xamplc 28.11 thc valucs ol thc emp_no column ol thc
employee tablc lorm thc top clcmcnt in thc rcsulting XML lragmcnt. Thc valucs ol thc
job column ol thc works_on tablc lorm a subclcmcnt within thc top clcmcnt.
Cha pt er 2 8: S QL S er ver a nd XML 665
XPLICI7 Mode
As you can scc lrom xamplc 28.11, thc rcsult sct in AUT modc is displaycd as a
simplc, ncstcd XML trcc. Thc qucrics in AUT modc arc good il you want to gcncratc
simplc hicrarchics, bccausc this modc providcs littlc control ovcr thc shapc ol thc XML
documcnt gcncratcd lrom a qucry rcsult.
!l you want to spccily thc cxtcndcd lorm ol thc rcsult sct, you can usc thc FR
XML XPL!C!T option. Vith this option, thc rcsult sct is displaycd as a univcrsal
tablc that has all thc inlormation about thc rcsulting XML trcc. Thc data in thc tablc
is vcrtically partitioncd into groups. ach group thcn bccomcs an XML clcmcnt in thc
rcsult sct.
xamplc 28.12 shows thc usc ol XPL!C!T modc.
XAMPL 28.12
US samplc,
SLCT 1 AS tag, NULL as parcnt,
cmp_lnamc AS |cmploycc!1!cmp_lnamc|,
NULL AS |works_on!2!job|
FRM cmploycc
UN!N
SLCT 2, 1, cmp_lnamc, works_on.job
FRM cmploycc, works_on
VHR cmploycc.cmp_no - 10000
AN cmploycc.cmp_no - works_on.cmp_no
RR 8Y |cmploycc!1!cmp_lnamc|
FR XML XPL!C!T,
Thc rcsult is
cmploycc cmp_lnamc-"8arrimorc " /~
cmploycc cmp_lnamc-"8crtoni "~
works_on job-"Clcrk " /~
works_on job-"Managcr " /~
/cmploycc~
cmploycc cmp_lnamc-"Hanscl "~
works_on job-"Analyst " /~
/cmploycc~
cmploycc cmp_lnamc-"Jamcs " /~
cmploycc cmp_lnamc-"Joncs " /~
cmploycc cmp_lnamc-"Moscr " /~
cmploycc cmp_lnamc-"Smith " /~
666 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
As you can scc lrom thc SLCT statcmcnt in xamplc 28.12, thc FR XML
XPL!C!T option rcquircs two additional mctadata columns: tag and parent. (Thcsc
two columns arc uscd to dctcrminc thc primary kcy/lorcign kcy rclationship in thc
XML trcc.) Thc tag column storcs thc tag numbcr ol thc currcnt clcmcnt, whilc thc
parent column storcs thc tag numbcr ol thc parcnt clcmcnt. (Thc parcnt tablc is thc
tablc with thc primary kcy.) !l thc parcnt tag is NULL, thc row is placcd dircctly undcr
thc root clcmcnt.
|c sc| ase |/|||t| mc1e |e:case c/ ||s :cm(|es||,. |se |/| mc1e |ss|ec1 (1|s:asse1 ses|.

PA7H Mode
All ol thc thrcc FR XML options dcscribcd abovc havc dillcrcnt disadvantagcs and
rcstrictions. Thc FR XML RAV option supports only onc lcvcl ol ncsting, whilc thc
FR XML AUT option rcquircs that all columns sclcctcd lrom thc samc tablc occur
at thc samc lcvcl. Also, both options do not allow mixing ol clcmcnts and attributcs
in thc samc XML documcnt. n thc othcr hand, thc FR XML XPL!C!T option
allows mixing ol clcmcnts and attributcs, but thc syntax ol this option is cumbcrsomc,
as you can scc lrom thc prcvious cxamplc.
Thc FR XML PATH option allows you to implcmcnt in a vcry casy way almost
all qucrics that rcquirc XPL!C!T modc. !n PATH modc, column namcs or column
aliascs arc trcatcd as XPath cxprcssions, which indicatc how thc valucs arc bcing
mappcd to XML. (An XPath cxprcssion consists ol a scqucncc ol nodcs, possibly
scparatcd by /. For cach slash, thc systcm crcatcs anothcr lcvcl ol hicrarchy in thc
rcsulting documcnt.)
xamplc 28.13 shows thc usc ol PATH modc.
XAMPL 28.13
US samplc,
SLCT d.dcpt_namc "Ccpartmcnt",
cmp_lnamc "mpNamc/First",
cmp_lnamc "mpNamc/Last"
FRM mploycc c, dcpartmcnt d
VHR c.dcpt_no - d.dcpt_no
AN d.dcpt_no - 'd1'
FR XML PATH,
Cha pt er 2 8: S QL S er ver a nd XML 667
Thc rcsult is
row cpartmcnt-"Rcscarch "~
mpNamc~
First~John /First~
Last~8arrimorc /Last~
/mpNamc~
/row~
row cpartmcnt-"Rcscarch "~
mpNamc~
First~Sybill /First~
Last~Moscr /Last~
/mpNamc~
/row~
!n PATH modc, thc column namcs arc uscd as thc path in constructing an XML
documcnt. Thc column containing dcpartmcnt namcs starts with C. This mcans that
thc Department attributc is addcd to thc row~ clcmcnt. All othcr columns includc a /
in thc column namc, indicating hicrarchy. For this rcason, thc rcsulting XML documcnt
will havc thc mpNamc~ child undcr thc row~ clcmcnt and First~ and Last~
clcmcnts at thc ncxt sublcvcl.
Directives
SQL Scrvcr supports scvcral dillcrcnt dircctivcs that allow you to producc dillcrcnt
rcsults whcn you want to display XML documcnts and lragmcnts. Thc lollowing list
shows scvcral ol thcsc dircctivcs:
TYP
LMNTS (with XS!N!L)
RT
Thc lollowing subscctions dcscribc thcsc dircctivcs.
7YP Directive
SQL Scrvcr allows you to storc thc rcsult ol a rclational qucry as an XML documcnt
or lragmcnt in thc XML data typc by using thc TYP dircctivc. Vhcn thc TYP
dircctivc is spccilicd, a qucry with thc FR XML option rcturns a oncrow,
668 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
onccolumn rcsult sct. (This dircctivc is a common dircctivc, mcaning you can usc it in
all lour modcs.) xamplc 28.14 shows thc usc ol thc TYP dircctivc with AUT modc.
XAMPL 28.14
US samplc,
CLAR Cx xml,
ST Cx - (SLCT FRM dcpartmcnt
FR XML AUT, TYP),
SLCT Cx,
Thc rcsult is
dcpartmcnt dcpt_no-"d1 " dcpt_namc-"Rcscarch " location-"allas " /~
dcpartmcnt dcpt_no-"d2 " dcpt_namc-"Accounting " location-"Scattlc " /~
dcpartmcnt dcpt_no-"d3 " dcpt_namc-"Markcting " location-"allas " /~
xamplc 28.14 lirst dcclarcs thc variablc x as a local variablc ol thc XML data typc
and assigns thc rcsult ol thc SLCT statcmcnt to it. Thc last SLCT statcmcnt in
thc batch displays thc contcnt ol thc variablc.
LMN7S Directive
As you alrcady know lrom Chaptcr 3, atabasc nginc supports NULL valucs to
spccily unknown (or missing) valucs. !n contrast to thc rclational modcl, XML docs not
support NULL valucs, and thosc valucs arc omittcd in thc rcsult scts ol qucrics with thc
FR XML option.
SQL Scrvcr allows you to display thc missing valucs in an XML documcnt by using
thc LMNTS dircctivc with thc XS!N!L option. Gcncrally, thc LMNTS
dircctivc constructs thc corrcsponding XML documcnt so that cach column valuc
maps to an clcmcnt. !l thc column valuc is NULL, no clcmcnt is addcd by dclault. 8y
spccilying thc additional XS!N!L option, you can rcqucst that an clcmcnt bc crcatcd
lor thc NULL valuc as wcll. !n this casc, an clcmcnt with thc XS!N!L attributc sct to
truc is rcturncd lor cach NULL valuc in thc column.
ROO7 Directive
Gcncrally, qucrics with thc FR XML option producc XML lragmcntsXML
without a corrcsponding root clcmcnt. This can bc a problcm il an AP! acccpts only
XML documcnts as input. SQL Scrvcr allows you to add thc root clcmcnt using thc
RT dircctivc. 8y spccilying thc RT dircctivc in thc FR XML qucry, you can
rcqucst a singlc, toplcvcl clcmcnt lor thc rcsulting XML. (Thc argumcnt spccilicd lor
thc dircctivc providcs thc root clcmcnt.)
Cha pt er 2 8: S QL S er ver a nd XML 669
xamplc 28.15 shows thc usc ol thc RT dircctivc.
XAMPL 28.15
US samplc,
SLCT FRM dcpartmcnt
FR XML AUT, RT ('Allcpartmcnts'),
Thc rcsult is
Allcpartmcnts~
dcpartmcnt dcpt_no-"d1 " dcpt_namc-"Rcscarch " location-"allas " /~
dcpartmcnt dcpt_no-"d2 " dcpt_namc-"Accounting " location-"Scattlc " /~
dcpartmcnt dcpt_no-"d3 " dcpt_namc-"Markcting " location-"allas " /~
/Allcpartmcnts~
Thc qucry in xamplc 28.15 displays thc XML lragmcnt with all rows lrom thc
department tablc. Thc RT dircctivc adds thc root spccilication in thc rcsult sct
with thc AllDepartments paramctcr as thc root namc.
SL Server Xuery Metbods
XQucry is thc ncw qucry languagc lor XML. This languagc is much morc complcx
than XPath (As a mattcr ol lact, XQucry contains X Path as a sublanguagc.) You can
convcrt thc data in rclational and XML columns to an XML data typc instancc using
FR XML with thc TYP dircctivc and qucry it by using XQucry. SQL Scrvcr
supports livc mcthods that can bc uscd to qucry XML documcnts with XQucry:
query() Acccpts an XQucry statcmcnt as input and rcturns an instancc ol thc
XML data typc.
exist() Acccpts an XQucry statcmcnt as input and rcturns 0, 1, or NULL,
dcpcnding on thc qucry rcsult.
value() Acccpts an XQucry statcmcnt as input and rcturns a singlc scalar valuc.
nodes() XML data typc instancc
into rclational data. !t allows you to idcntily nodcs that will bc mappcd into a ncw row.
modify() !n contrast to thc standardizcd vcrsion ol XQucry, which in its \crsion
modify()
mcthod.
670 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
ca :cs /|s1 1e|c||e1 1es:/|(||css c/ /9ae/, |s 3cc|s 0s||se.

Thc lollowing two cxamplcs show thc usc ol two XQucry mcthods. xamplc 28.16
shows thc usc ol thc query() mcthod.
XAMPL 28.16
US samplc,
SLCT xml_column.qucry('/PcrsonList/Titlc')
FRM xmltab
FR XML AUT, TYP,
Thc rcsult is
xmltab~
Titlc~ \aluc-"mploycc List"&gt,/Titlc~
/xmltab~
Thc SLCT list ol thc qucry in xamplc 28.16 contains thc query() mcthod with
an XPath cxprcssion. (Notc that thc SQL Scrvcr XQucry mcthods arc applicd using
dot notation.) Thc cxprcssion '/PcrsonList/Titlc' is an absolutc cxprcssion, whcrc thc
valuc ol thc Title clcmcnt is rctricvcd. (Rcmcmbcr that XPath cxprcssions arc valid
XQucry statcmcnts bccausc XPath is a sublanguagc ol XQucry.)
As you alrcady know, thc exist() mcthod acccpts an XQucry statcmcnt as input and
rcturns 0, 1, or NULL, dcpcnding on thc qucry rcsult. !l thc qucry rcsult is an cmpty
scqucncc, thc rcturn valuc is 0. A scqucncc with at lcast onc itcm rcturns 1, and NULL
is rcturncd il thc valuc ol thc column is NULL. xamplc 28.17 shows thc usc ol thc
exist() mcthod.
XAMPL 28.17
SLCT xml_column.cxist('/PcrsonList/Titlc/C\aluc-mployccList') AS a
FRM xmltab
FR XML AUT, TYP,
Thc rcsult is
xmltab a-"1" /~
Cha pt er 2 8: S QL S er ver a nd XML 671
Thc SLCT list ol thc qucry in xamplc 28.17 contains thc exist() mcthod with
an XPath cxprcssion that tcsts whcthcr thc Value attributc ol thc XML documcnt has
thc valuc EmployeeList. Thc tcst is cvaluatcd to truc, and thcrclorc thc rcturn valuc ol
thc qucry is 1.
SL Server 2008 and XML nbancements
SQL Scrvcr 2008 has thc lollowing minor changcs in rclation to thc XML Schcma
support:
!mprovcd support lor thc xsdateTime, xsdate and xstime tcmporal lunctions.
!mprovcd support lor thc xslist and xsunion lunctions.
As you alrcady know lrom Chaptcr 4, SQL Scrvcr 2008 supports ncw data typcs
AT and T!M. Thc corrcsponding XML Schcma data typcs arc supportcd, too.
You can usc XML schcmas to dclinc data typcs lor your XML data that allow a
limitcd sct ol valucs to bc assigncd to multivaluc clcmcnts and attributcs. nc ol thcm
is xslist, which is now supportcd. Also, SQL Scrvcr 2008 adds support lor union typcs
that contain list typcs, which you can usc to mcrgc multiplc list typc dclinitions and
rcstrictions into a singlc typc.
8csidcs thcsc two cnhanccmcnts, thc systcm supports thc sqlvariable and sqlcolumn
lunctions on a paramctcr ol thc XML data typc.
ConcIusion
SQL Scrvcr has lull support lor XML. Thc most important lcaturc is thc cxistcncc ol
thc XML data typc, which allows thc databasc systcm to storc XML documcnts as lirst
class objccts.
Thc valucs ol thc XML data typc can bc schcma validatcd il onc or morc schcmas
arc associatcd with this typc. You can dctcrminc thc cxact data typcs ol clcmcnts and
attributcs only il thc corrcsponding XML documcnt contains typcs spccilicd by XML
schcmas. Schcma dclinitions arc spccilicd using thc CRAT XML SCHMA
CLLCT!N statcmcnt.
XML also has its own qucry languagcs, thc most important ol which is XQucry.
SQL Scrvcr supports scvcral nonstandard mcthods that can bc uscd to qucry XML
documcnts with XQucry.
Thc ncxt chaptcr dcscribcs spatial data.
This page intentionally left blank
In 7bis Cbapter
Presenting SpatiaI Data
SpatiaI Data 7ypes
Introductlon to
Spatlal Iata
Cbapter 29
Copyright 2008 by The McGraw-Hill Companies. Click here for terms of use.
674 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de

n thc past lcw ycars, thc nccd ol busincsscs to incorporatc gcographic data into
thcir databascs and to managc it using a databasc systcm has grown signilicantly.
Thc most important lactor lcading to this growth is thc prolilcration ol gcograph
ical scrviccs and dcviccs, such as Microsolt \irtual arth and lowpriccd GPS dcviccs.
Gcncrally, thc support ol spatial data by a databasc vcndor hclps uscrs to makc bcttcr
dccisions in scvcral sccnarios, such as:
Rcalcstatc analysis ("Find a suitablc propcrty within 500m ol an clcmcntary
school.")
Consumcrbascd inlormation ("Find thc ncarcst shopping malls to a givcn Z!P
codc.")

Thc lirst part ol this chaptcr introduccs two dillcrcnt spatial modcls. Altcr that, thc
GMTRY data typc and thc corrcsponding mcthods arc discusscd in dctail. Finally,
thc practical usc ol thc mcthods in qucrics will bc shown.
Presenting SpatiaI Data
Gcncrally, thcrc arc two dillcrcnt groups ol modcls lor prcscnting spatial data:
Gcodctic spatial modcls
Flat spatial modcls
Thc lollowing scctions dcscribc thcsc two groups.
Ceodetic SpatiaI ModeIs
Plancts arc complcx objccts that can bc rcprcscntcd using a llattcncd sphcrc (callcd a
spheroid). A good approximation lor thc rcprcscntation ol arth (and othcr plancts)
is a globc, whcrc locations on thc surlacc arc dcscribcd using latitudc and longitudc.
(Latitudc givcs thc location ol a placc on arth north or south ol thc cquator, whilc
longitudc spccilics thc location in rclation to a choscn mcridian.) Modcls that usc thcsc
mcasurcs arc callcd geodetic models. 8ccausc thcsc modcls providc a good approximation
ol sphcroids, thcy providc thc most accuratc way to rcprcscnt spatial data.
Cha pt er 2 9: | nt r oduc t i on t o S pa t i a l Dat a 675
FIat SpatiaI ModeIs
Flat spatial modcls (or planar modcls) usc twodimcnsional maps to rcprcscnt arth.
!n this casc, thc sphcroid is llattcncd and projcctcd in a planc. Thc llattcning proccss
rcsults in somc dclormation ol shapc and sizc ol thc projcctcd (gcographic) objccts.
Flat spatial modcls work bcst lor small surlacc arcas, bccausc thc largcr thc surlacc arca
bcing rcprcscntcd, thc morc dclormation that occurs.
SpatiaI Data 7ypes
SQL Scrvcr 2008 providcs two spatial data typcs:
GEOGRAPHY Rcprcscnts spatial data in gcodctic spatial modcls
GEOMETRY
8oth data typcs arc implcmcntcd using CLR, and can bc uscd to storc dillcrcnt
kinds ol gcographical clcmcnts such as points, lincs, and polygons.
Thc lollowing scction dcscribcs thc GMTRY data typc in dctail and givcs
somc cxamplcs ol how you can usc it. 8ccausc thc GGRAPHY data typc is vcry
similar to thc GMTRY data typc, only thc GMTRY data typc is dcscribcd
in dctail, but a short scction dcscribing thc dillcrcnccs bctwccn thc two data typcs
wraps up thc chaptcr.
CDM7RY Data 7ype
An cxamplc will hclp to cxplain thc usc ol thc GMTRY data typc. xamplc 29.1
crcatcs a tablc lor nonalcoholic bcvcragc markcts in a givcn city (or statc).
XAMPL 29.1
US samplc,
CRAT TA8L bcvcragc_markcts
(id !NTGR !NT!TY(1,1),
namc \ARCHAR(25),
shapc GMTRY),
!NSRT !NT bcvcragc_markcts
\ALUS ('Cokc', gcomctry::STGcomFromTcxt
('PLYGN ((0 0, 150 0, 150 150, 0 150, 0 0))', 0)),
!NSRT !NT bcvcragc_markcts
\ALUS ('Pcpsi', gcomctry::STGcomFromTcxt
('PLYGN ((300 0, 150 0, 150 150, 300 150, 300 0))', 0)),
676 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
!NSRT !NT bcvcragc_markcts
\ALUS ('7UP', gcomctry::STGcomFromTcxt
('PLYGN ((300 0, 150 0, 150 150, 300 150, 300 0))', 0)),
!NSRT !NT bcvcragc_markcts
\ALUS ('Almdudlcr', gcomctry::STGcomFromTcxt
('P!NT (50 0)', 0)),
Thc bcvcragc_markcts tablc has thrcc columns, ol which thc lirst onc is just thc
id column, whilc thc sccond, name, contains thc bcvcragc namc. Thc third column,
shape, spccilics thc shapc ol thc markct arca in which thc particular bcvcragc is thc
most prclcrrcd onc. Thc lirst thrcc !NSRT statcmcnts crcatc thrcc arcas in which
a particular bcvcragc is most prclcrrcd. All thrcc arcas happcn to bc a polygon. Thc
lourth !NSRT statcmcnt inscrts a point, bccausc thcrc is just onc placc whcrc thc
particular bcvcragc (Almdudlcr) can bc bought.
As you can scc lrom xamplc 29.1, thc STGeomIromText() mcthod is uscd to
inscrt thc coordinatcs ol gcomctric ligurcs, such as polygons and points. This mcthod
bclongs to a group ol static gcography mcthods, discusscd ncxt. Altcr that spatial
indcxing will bc discusscd in dctail.
Static Ceometry Methods
Using thc GMTRY data typc, you can spccily spatial prcdicatcs on instanccs
ol spatial gcomctrics within standard SQL statcmcnts. Thcsc prcdicatcs usc spccial
mcthods to pcrlorm spatial opcrations such as calculating distanccs bctwccn locations.
(Thc samc is truc lor thc GGRAPHY data typc.)
SQL Scrvcr 2008 supports thc static gcomctry mcthods spccilicd by thc pcn
Gcospatial Consortium (GC). GC is a nonprolit organization that is lcading thc
dcvclopmcnt ol standards lor spatial data. Thc aim ol thc organization is to providc thc
ncccssary spccilication lor lcaturcs in rclation to spatial data. Thc task ol thc soltwarc
vcndors is to implcmcnt thc wholc or part ol thc spccilication. (Thc vcndors somctimcs
implcmcnt somc nonstandard lcaturcs, too.)
Thc list ol static gcomctry mcthods spccilicd by GC and implcmcntcd by
Microsolt is rathcr long. For this rcason, just lour mcthods that can bc applicd to thc
GMTRY data typc arc introduccd hcrc:
STGeomIromText() Rcturns an instancc ol thc GMTRY data typc lrom
thc VcllKnown Tcxt (VKT) rcprcscntation, augmcntcd with thc corrcsponding
rcprcscnting vcctor gcomctry objccts.)
Cha pt er 2 9: | nt r oduc t i on t o S pa t i a l Dat a 677
STPointIromText() Rcturns thc VKT rcprcscntation ol a P!NT instancc.
STLineIromText() Rcturns thc VKT rcprcscntation ol a L!NSTR!NG
instancc augmcntcd with thc corrcsponding clcvation and mcasurc valucs.
STPolyIromText() Rcturns thc VKT rcprcscntation ol a MULT!PLYGN
instancc augmcntcd with thc corrcsponding clcvation and mcasurc valucs.
3es|1es s|c||: ecme|/, me||c1s, ||e/e c/e c||e/ ecme|/, me||c1s ||c| c/e ase1 a||| ||e |/| s|c|emes|s,
||e, c/e es(|c|se1 c ||| |c|e/ |s ||e se:||cs 9ae/,|s ||e |0/|| |c|c.
SpatiaI Indexing
As you alrcady know lrom Chaptcr 10, indcxing is gcncrally uscd to providc last acccss
to data. Thcrclorc, spatial indiccs arc ncccssary to spccd up rctricval opcrations on
spatial data.
A spatial indcx is dclincd on a tablc column ol thc GMTRY or GGRAPHY
data typc. !n SQL Scrvcr 2008, spatial indiccs arc built using 8trccs, which mcans that
thc indiccs rcprcscnt two dimcnsions in thc lincar ordcr ol 8trccs. Thcrclorc, bclorc
rcading data into a spatial indcx, SQL Scrvcr 2008 implcmcnts a hicrarchical unilorm
dccomposition ol spacc. Thc indcxcrcation proccss dccomposcs thc spacc into a lour
lcvcl grid hicrarchy.
|e/e c/e se|e/c| |,(es c/ |s1|:es ||c| c/e ase1 es(e:|c||, /c/ s(c||c| 1c|c. |e mcs| |m(c/|cs| cse |s :c||e1
|-|/ee |s1es. |c(e/a||, |||s |s1es |,(e a||| |e |m(|emes|e1 |, /|:/csc/| |s c sa|seaes| |e/s|cs c/ :9| :e/|e/.
Thc CRAT SPAT!AL !NX statcmcnt is uscd to crcatc a spatial indcx.
Thc gcncral lorm ol this statcmcnt is similar to thc convcnicnt CRAT !NX
statcmcnt, but contains additional options and clauscs, somc ol which arc introduccd
hcrc:
GEOMETRY_GRD clause
that you arc using. (Tcsscllation is a proccss that is pcrlormcd altcr rcading thc
hicrarchy by associating it with a sct ol grid cclls that it touchcs.) GMTRY_
678 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
BOUNDNG_BOX option
lour coordinatcs ol thc bounding box: thc xmin and ymin coordinatcs ol thc
lowcrlclt corncr, and thc xmax and ymax coordinatcs ol thc uppcrright corncr.
GEOGRAPHY_GRD clause
xamplc 29.2 shows thc crcation ol a spatial indcx lor thc shape column ol thc
beverage_markets tablc.
XAMPL 29.2
US samplc,
G
ALTR TA8L bcvcragc_markcts
A CNSTRA!NT prim_kcy PR!MARY KY(id),
G
CRAT SPAT!AL !NX i_spatial_shapc
N bcvcragc_markcts(shapc)
US!NG GMTRY_GR!
V!TH (
8UN!NG_8X - ( xmin-0, ymin-0, xmax-500, ymax-200 ),
GR!S - (LV, LV, M!UM, H!GH),
PA_!NX - N ),
A spatial indcx can bc crcatcd only il thc primary kcy lor thc tablc with a spatial data
column is cxplicitly dclincd. For this rcason, thc lirst statcmcnt in xamplc 29.2 is thc
ALTR TA8L statcmcnt, which dclincs this constraint.
Thc subscqucnt CRAT SPAT!AL !NX statcmcnt crcatcs thc indcx using
thc GMTRY_GR! clausc. Thc 8UN!NG_8X option spccilics thc
boundarics insidc which thc instancc ol thc shape column will bc placcd. Thc GR!S
option spccilics thc dcnsity ol thc grid at cach lcvcl ol a tcsscllation schcmc. (Thc
PA_!NX option is dcscribcd in Chaptcr 10.)
SQL Scrvcr 2008 supports, among othcrs, two catalog vicws rclatcd to spatial data:
sys.spatial_indcxcs
sys.spatial_indcx_tcsscllations
Cha pt er 2 9: | nt r oduc t i on t o S pa t i a l Dat a 679
Thc sys.spatial indexes vicw rcprcscnts thc main indcx inlormation ol thc spatial
indiccs. Using thc sys.spatial_index_tessellations vicw, you can display thc inlormation
about thc tcsscllation schcmc and paramctcrs ol cach ol thc cxisting spatial indiccs.
xamplc 29.3 shows thc inlormation that can bc displaycd using this vicw.
XAMPL 29.3
SLCT objcct_id, namc, typc_dcsc
FRM sys.spatial_indcxcs
Thc rcsult is
0h[ect_|6 aame tpe_6esc
+zzI |_.j+t|+|_.|+je :||I|||
Querying the COM7RY Data
Spatial data can bc qucricd thc samc way rclational data is qucricd. SQL scrvcr supports
many gcomctry mcthods lor qucrying spatial data. Thc lollowing cxamplcs show a
samplc ol thc inlormation that can bc lound lrom thc contcnt ol thc shape column ol
thc beverage_markets tablc.
xamplc 29.4 shows thc usc ol thc STContains() mcthod.
XAMPL 29.4
ocs thc shop that sclls Almdudlcr lic in thc arca whcrc Cokc is thc prclcrrcd
bcvcragc:
CLAR Cg gcomctry,
CLAR Ch gcomctry,
SLCT Ch - shapc FRM bcvcragc_markcts VHR namc -'Almdudlcr',
SLCT Cg - shapc FRM bcvcragc_markcts VHR namc - 'Cokc',
SLCT Cg.STContains(Ch),
Thc rcsult is 0.
Thc STContains() mcthod rcturns 1 il an instancc ol thc GMTRY data typc
complctcly contains anothcr instancc ol thc samc typc. Thc rcsult ol xamplc 29.4
mcans that thc shop that sclls Almdudlcr docs not bclong to thc arca whcrc thc prclcrrcd
bcvcragc is Cokc.
xamplc 29.5 shows thc usc ol thc STLength() mcthod.
680 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
XAMPL 29.5
Find thc lcngth and thc VKT rcprcscntation ol thc shape column lor thc Almdudlcr
shop:
SLCT id, shapc.ToString() AS wkt, shapc.STLcngth() AS lcngth
FRM bcvcragc_markcts
VHR namc - 'Almdudlcr' ,
Thc rcsult is
|6 wkt |eaqth
+ |0|NI (! }
Thc STLength() mcthod in xamplc 29.5 rcturns thc total lcngth ol thc clcmcnts
ol thc GMTRY data typc. (Thc rcsult is 0, bccausc thc displaycd valuc is a
point.) Thc ToString() mcthod is thc gcncral mcthod that loads an cntirc collcction
ol variablcs with a singlc mcthod call. !n xamplc 29.5, this mcthod is uscd to load all
propcrtics ol thc givcn point and to display it using thc VKT rcprcscntation.
xamplc 29.6 shows thc usc ol thc STntersects() mcthod.
XAMPL 29.6
ocs thc rcgion that sclls Cokc intcrscct with thc rcgion that sclls Pcpsi:
US samplc,
CLAR Cg gcomctry,
CLAR Ch gcomctry,
SLCT Ch - shapc FRM bcvcragc_markcts VHR namc -'Cokc',
SLCT Cg - shapc FRM bcvcragc_markcts VHR namc - 'Pcpsi',
SLCT Cg.ST!ntcrsccts(Ch),
Thc STntersects() mcthod in xamplc 29.6 is applicd to both rcgions to lind out
whcthcr thc rcgions intcrscct. (Thc valuc 1 mcans that thc rcgions intcrscct.)
3es|1es ||e me||c1s ase1 |s ||e (/e:e1|s escm(|es, ||e/e c/e mcs, c||e/ scss|c||: ecme|/, me||c1s, a||:|
c/e 1es:/||e1 |s 1e|c|| |s 3cc|s 0s||se.
Cha pt er 2 9: | nt r oduc t i on t o S pa t i a l Dat a 681
Differences etween tbe CDM7RY
and CDCRAPHY Data 7ypes
As you alrcady know, thc GMTRY data typc is uscd in llat spatial modcls, whilc
thc GGRAPHY data typc is uscd in gcodctic modcls. Thc main dillcrcncc bctwccn
thcsc two groups ol modcls is that with thc GMTRY data typc, distanccs and
arcas arc givcn in thc samc unit ol mcasurcmcnt as thc coordinatcs ol thc instanccs.
(Thcrclorc, thc distancc bctwccn thc points (0,0) and (3,4) will always bc 5 units.)
This is not thc casc with thc GGRAPHY data typc, which works with cllipsoidal
coordinatcs that arc cxprcsscd in dcgrccs ol latitudc and longitudc.
Thcrc arc also somc rcstrictions placcd on thc GGRAPHY data typc. For
cxamplc, cach instancc ol thc GGRAPHY data typc must lit insidc a singlc
hcmisphcrc. (Largcr spatial objccts arc not allowcd and will causc an crror.)
ConcIusion
SQL Scrvcr 2008 supports two spatial data typcs: GGRAPHY and GMTRY.
Thc GGRAPHY data typc is uscd to rcprcscnt spatial data in gcodctic modcls,
whilc thc GMTRY data typc is uscd with llat spatial modcls. To work with
thcsc data typcs, you nccd a sct ol corrcsponding opcrations (i.c. mcthods). Microsolt
implcmcntcd thc static gcomctry mcthods spccilicd by GC. 8csidcs thc supportcd
static gcomctry mcthods, thcrc is anothcr group ol implcmcntcd mcthods that can bc
uscd to rctricvc spatial data.
This page intentionally left blank
683
Index
- (m|aa. .|a}, +
.!! cemm+aa, +z
r|M||||| |ewera, +
r||9J|||| |ewera, +
||.| I|me ceaater, !1z
|aterrajt I|me ceaater, !z
|rece..er I|me ceaater, !z
-! ejt|ea, +
yyC0NN|CI|0N: .+r|+||e, I
yyC|J_|J:\ .+r|+||e, I
yyerrer |e|+| .+r|+||e, 1+
yy|||0| .+r|+||e, I
yy|||NI|I\ .+r|+||e,
yy||N0|| .+r|+||e,
yy||N0J|0| .+r|+||e,
yy||0C|| .+r|+||e,
yy|0\C0JNI .+r|+||e,
yy:||\||N|M| .+r|+||e,
yy:||| .+r|+||e,
yytr+aceaat |e|+| .+r|+||e, 1!
yy\||:|0N .+r|+||e,
y|+a j+r+meter, +z
yM|/_C0NN|CI|0N: .+r|+||e,
ym.aam j+r+meter, +z
yeraer j+r+meter, 1II
y.e.er|t j+r+meter, +z
yw|t|_|e j+r+meter, +z
' (aea||e aet+t|ea m+r|.},
N| (l|r.t aerm+| lerm}, 1
' (.|a|e aet+t|ea m+r|.},
zN| (.eceaa aerm+| lerm}, 1-+
1N| (t||ra aerm+| lerm}, +-!
1z-||t :9| :er.er ea|t|ea, z1
+-||t :9| :er.er ea|t|ea, z1
A
||:(a} laact|ea,
+cce..|a rejert., -z
|cceaat |re.|.|ea|a t+|, 11-1+
+cceaat., 11, 1-1I
|C0:(a} laact|ea,
+ct|.+t|a +jj||c+t|ea re|e., 1z1
+a |ec aer|e., ++
||| C0N:I|||NI c|+a.e,
|aa |||e a|+|e |e\, !1
+aare.. .j+ce, !z!
|aa\|t|\+|ae( } met|ea, 1z
|a.+acea Iaa|a 0jt|ea. a|+|e |e\, !+
+llect|a |ec|., 1!-1!I
||I|| a+tet|me c|+a.e, +1+
+lter |m+e., 1!
||I|| tr|er., 1-1I!
+re+te laact|ea.
cea.ea|eat, , +-!1
e.er.|ew, I-
.t+t|.t|c+|, !!
a.er-ael|aea, !!
+re+t|ea
ae.|a|a, !I1-!I
aeterm|a|a |e.e| el, !!-!
+|ert., +!I-+1
+||+. a+t+ tje., -1
||| ejer+ter, +!-+I
||| ejt|ea,
||| :||\|| c|+a.e, 1I
+||ec+t|ea aa|t., 1I
|||0\_||0|_|0C|: ejt|ea, z!
|||0\_|0\_|0C|: ejt|ea, z!
Copyright 2008 by The McGraw-Hill Companies. Click here for terms of use.
684 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
||I|| |||||C|I|0N |0|| .t+temeat, 1z1
||I|| |::|M||\ .t+temeat, z1z
||I|| |JI|0||l|I|0N .t+temeat, 1!
||I|| C0|JMN c|+a.e, I
||I|| ||I|||:| .t+temeat, +, 1, +1I, +
||I|| |JNCI|0N .t+temeat, z+
||I|| |N||/ .t+temeat, z, !
||I|| |00|N .t+temeat, 1
||I|| jerm|..|ea, 1z
||I|| ||0C||J|| .t+temeat, zzI
||I|| |0|| .t+temeat, 1z+
||I|| :C||M| .t+temeat, 1+-1!
||I|| I|||| .t+temeat, , , 1!!
||I|| I||00|| .t+temeat, 1-1I, 1II
||I|| J:|| .t+temeat, 1I
||I|| \||\ .t+temeat, z+-z!
||I|| /M| :C||M| C0|||CI|0N .t+temeat, !
+|ter|a
|aa|ce., z-zI
.|ew., z+-z!
|a+|.|. :er.|ce.. M|cre.elt |a+|.|. :er.|ce.
|a+|.|. :er.|ce. Ceal|ar+t|ea j+e, 1+
+a+|t|c ..tem., !!
+a+|t|c+| t+.|., z1
+ac|er aer|e.,
|N| ejer+ter., 1
|N:|_NJ||: ejt|ea, z+
|N:|_|||||N0 ejt|ea, z+
|N:|_\||N|N0: ejt|ea, z+
|N\ ejer+ter, +!-+I
+jj||c+t|ea re|e., 1zz-1z+
+jj||c+t|ea-ceae ell|c|eac, !
||||\ ejer+ter, !, z1-z+
+rameat., z1!
+rt|c|e., +I-+I
|: :N||:|0I 0| c|+a.e, !
|:C ejt|ea, z1
|:C||(c|+r+cter} laact|ea, 1
|:|N(a} laact|ea,
+..em||_a+me.c|+.._a+me.met|ea_a+me c|+a.e, z1z
+.mmetr|c |e eacrjt|ea, 1
|:\MM|I||C ||\ ejt|ea, 1
|I|N(a} laact|ea,
|INz(a,m} laact|ea,
+tem|c +ttr||ate., 1
+tem|c|t jrejert, 1+I
+ttr||ate.
ael|aea, !
/M|, +!-+I
+aa|t tr+||., 1I-1Iz
+at|eat|c+t|ea
c|ee.|a meae., zI
ael|aea, I, 1z
eacrjt|a a+t+, 1+-1
|mj|emeat|a meae., 1+
m+a+|a |e|a. w|t| M+a+emeat :taa|e, 1
e.er.|ew, 11-1+
.ett|a aj ..tem .ecar|t a.|a |||, 1-1
|at|eat|c+t|ea l|e|a, +1
+at|er|a +ct|.|t|e., !I-1
+at|er|t+t|ea, I, 1z, 1z-11+
|ate ||ae ejt|ea, +!
|JI0 meae, +
|JI0 ejt|ea, 1!!
|JI0_C|0:| ejt|ea,
|JI0_C|||I|_:I|I|:I|C: ejt|ea, , +, !I
+ate_cre+tea ce|ama, +
|JI0_J|||I|_:I|I|:I|C: ejt|ea, , +, !I
+aterewt| jrejert, !z
+atem+t|c rece.er, +z
+atem+t|a ..tem +am|a|.tr+t|ea t+.|.
+|ert., +!I-+1
je|., +!-+!
ejer+ter., +!+-+!!
:9| :er.er |eat, ++
|\0 laact|ea, , !1
+._lr+meat+t|ea_|a_jerceat ce|ama, zI
+._j+e_.j+ce_a.ea_|a_jerceat ce|ama, zI

|
+
-tree a+t+ .tractare, z!-zz
|+c| Jj |+t+|+.e a|+|e, +z1
||C|J| ||I|||:| .t+temeat, +-+z
|+c|aj |e.|ce a|+|e |e\, +zz
|+c|aj ae.|ce., +
| ndex 685
||C|J| |00 .t+temeat, +z
|+c|aj .et., +zI
|+c|aj.
a|llereat|+|, +!
l||e, +I
la|| a+t+|+.e, +!
||| +.+||+||||t, +1-++1
m+.ter a+t+|+.e, +z+-+z!
e.er.|ew, I
jreaact|ea a+t+|+.e., +z!
tr+a.+ct|ea |e, +!-+I
a.|a M+a+emeat :taa|e, +z-+z+
a.|a Ir+a.+ct-:9| .t+temeat., +-+z
|+tc|e., z, zzz, !!
|cj (|a|| Cej |rer+m} at|||t, 1-+
|elere |m+e., 1!
||0|N ||:I|||JI|| I||N:|CI|0N .t+temeat, 1+
||0|N .t+temeat, z
||0|N I||N:|CI|0N .t+temeat, 1+I, 1!, +1+
||I\||N ejer+ter, 1!-1I
||. |a.|ae.. |ate|||eace
|| |e.e|ejmeat :taa|e, !-!I
||0|NI a+t+ tje, I
||a+r +r|t|met|c ejer+ter., I
||N||\ a+t+ tje, I+-I!
||I a+t+ tje, I+-I!
||tm+j l||ter., 1!-1
||tm+j |aa|ce., 1!-1
||tw|.e ejer+ter., I
||ec| el .t+temeat., z-zI
||ec| ejt|ea, +
||0C|:|l| ejt|ea, +z
|ee|. 0a||ae (|0|}, +-+
|ee|e+a ejer+ter., I, 1-1+
|0JN||N0_|0/ ejt|ea, I
||||| .t+temeat, z
|rew.|a ca|e., !I-!II
|-tree .tractare., I
|aaet ce|ama, -
|aller C+c|e ||t |+t|e ceaater, !1
|a|| Cej |rer+m (|cj} at|||t, 1-+
|J|| |N:||I .t+temeat, +
|a||-|eea rece.er meae|, +1-+1I
|a.|ae.. |ate|||eace (||}
ca|e.
+re+t|ea, !!-!
e.er.|ew, !!-!!
j|.|c+| .ter+e el, !-!z
a+t+ +cce.., !z-!1
a+t+ m+rt., !!1-!!+
a+t+ j+rt|t|ea|a
+aa :9| :er.er z, 1z-1+
met|ea. el, z+-z!
t+||e., z!-1z, 1+
a+t+ w+re|ea.e., !!z-!!I
.t+r .c|em+ aer ejt|m|t+t|ea, 1+-1
.er.a. 0|I|, !!-!!z
Ir+a.+ct-:9| +aa
0|0J| |\ c|+a.e e\tea.|ea., !I-!1
aea.t+aa+ra +a+|t|c laact|ea., !I-1
0||| aer laact|ea., !1-!I
:9|/0|||, !-!
w|aaew cea.tract, !-!I
|a.|ae.. |ate|||eace |e.e|ejmeat :taa|e, !-!I
|a.|ae.. ra|e., 1I1
|\ ce|ama_a+me ejt|ea, I
|te. |ece|.ea/.ec ceaater, !11
|te. :eat/.ec ceaater, !11
|te. Iet+|/.ec ceaater, !11
C
-c cemm+aa_eaa ejt|ea, +
-c ejt|ea, +
c+c|ea rejert.,
c+aa|a+te |e., ,
c+ra|a+||t r+t|e,
C+rte.|+a jreaact, II
C|:C||| ejt|ea, , 11
C|:| e\jre..|ea., +-
C|:I(+ |: tje (|eat|}[ laact|ea, !
c+t+|e .|ew.
eacrjt|ea, 1
e.er.|ew, z++, z+
jerm|..|ea., 111
aer|a, z+I-z+
/M| :c|em+,
686 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
C|IC| .t+temeat, zz-zzz, 1+
C|C (c|+ae a+t+ c+jtare}, 11!-11, 1I
cac .c|em+, 11
C||||N0(a} laact|ea,
ce||., !Iz
ceatr+| jrece..|a aa|t. (C|J.}, !zz, !z-!z
ceatr+| ja|||.|er rej||c+t|ea meae|, +I-+II
ceatr+| .a|.cr||er rej||c+t|ea meae|, +II
C||I|||C|I| ejt|ea, 1
cert|l|c+te., 1-1
C|+ae |aterewt| a|+|e |e\, !z
c|+ae a+t+ c+jtare (C|C}, 11!-11, 1I
c|+ae., tr+c||a, 11+-11
C|||(a}[ a+t+ tje, Iz
c|+r+cter a+t+ tje, Iz
C|||(|ateer} laact|ea, 1
C||C| c|+a.e, 1-+
C||C| cea.tr+|at.,
c|ec|je|at., +z
C||C|:JM ejt|ea, +1
C|ee.e t|e |ej|emeat |ec+t|ea .tej, !
C|ee.e t|e I+||e |+eat j+e, +-!
C|ee.e t|e I+||e :t|e j+e, !
c||eat cemjeaeat., +
C||. Cemmea |+aa+e |aat|me
c|r_ea+||ea ejt|ea, zz, 1z
C|a.ter :er.|ce, ++z
C|a.terea |aae\ :ee| ejer+ter, +
c|a.terea |aa|ce., z-z
C|J:I|||| ejt|ea, , z1
c|a.terea t+||e., z-z
C0|||:C|(+

,+
z
,.} laact|ea, !
Ceaa, |. |., I,
Ceaeteae Cemmaa|t, +-+
C0|_||N0I|(e|j,ce|} laact|ea, !
ce|_a+me ce|ama, !I
C0|_N|M|(t+|_|a, ce|_|a} laact|ea,
C0|||I| ejt|ea, 1
Ce||+t|ea t+|, :er.er Ceal|ar+t|ea j+e, 1z-11
ce||ec+t|a t+||e., 1-1z
Ce|ama |rejert|e. t+|, !1-!+
ce|ama .t+t|.t|c., +
ce|ama .+|ae., 1I+
ce|ama_||.t, z
C0|JMN_N|M| ce|ama, z!
ce|ama-|e.e| cea.tr+|at.,
C0|JMN||0|||I\ laact|ea, , z!+
ce|ama.
+aa|a er arejj|a aew, -I
cemjatea, zI1-zI!
|aae\ea, +-+
je|a, zIz
mea|l|a jrejert|e. el, I
/M|, !-
cemmeat., I
C0MM|I .t+temeat, ++
C0MM|I I||N:|CI|0N .t+temeat, 1+, 1!
C0MM|I \0|| .t+temeat, 1+
Cemmea |+aa+e |aat|me (C||}
a+t+ tje., 1
.terea jreceaare. +aa, zz-z11
tr|er. +aa, 1-1!
J||., z+-z+
cemmea t+||e e\jre..|ea. (CI|.}, -!
Cemj+ct |a|t|ea el :9| :er.er, z!
cemj+r|.ea ejer+ter., +1-+!
cemj+t|||||t .|ew., z+I
Cemj|ete j+e, 1!
Cemj|et|a t|e \|t+ra j+e, !I
cemje.|te +ttr||ate., !
cemje.|te |aa|ce., z1
C0M|||::|0N ejt|ea, +z
C0M|JI| c|+a.e, -
cemjatea ce|ama., zI1-zI!
C0NC|I_NJ||_\||||:_NJ|| ejt|ea, , z+
ceacarreac
|.e|+t|ea |e.e|., 1!-1z
|ec||a, 1!-1!
meae|., 1++-1+!
e.er.|ew,
rew .er.|ea|a, 1z-1+
tr+a.+ct|ea., 1+-1!
aja+te., 11!
ceaa|t|ea., zI, +
| ndex 687
Ceal|are ||.tr||at|ea \|t+ra, +I
cealermea a|mea.|ea., !
Ceaaect te :er.er a|+|e |e\, +z-+1
Ceaaect te :9| :er.er a|+|e |e\, !-!
ceaaectea aer ea|t|a, !
Ceaaect|ea |rejert|e. a|+|e |e\, -
ceaaect|ea_||m|t_tr|er tr|er, 1
ceaaect|ea., tra.tea, 11
cea.|.teac jrejert, 1+I
cea.e||a+t|ea, !!z
cea.t+at.,
C0N:I|||NI ejt|ea, ,
C0N:I|||NI_C|I||00 ce|ama, z!
C0N:I|||NI_N|M| ce|ama, z!
C0N:I|||NI_:C||M| ce|ama, z!
cea.tr+|at.. |ater|t cea.tr+|at.
C0NI|NI |ewera,
Ceateat. |attea, +
C0NI|NJ| .t+temeat, z
C0NI|0| jerm|..|ea, 1z, 11-11
cea.ea|eat +re+te laact|ea., , +-!+
C0N\||I(tje(|eat|}[,+} laact|ea, !
cerre|+tea .a|aer|e., +1, 1-
C0:(a} laact|ea,
C0I(a} laact|ea,
C0JNI laact|ea, , !1-!+
C0JNI(} +re+te laact|ea, z1
C0JNI_||0 laact|ea, , !1-!+
ce.erea aer|e., z+, zIz
ce.er|a |aa|ce., z+, zIz-zI1
C|J. (ceatr+| jrece..|a aa|t.}, !zz, !z-!z
C|||I| |||||C|I|0N |0|| .t+temeat, 1zz-1z1
C|||I| |::|M||\ .t+temeat, z1, 11
C|||I| C||I|||C|I| .t+temeat, 1I-1
C|||I| ||I|||:| .t+temeat, z, !
C|||I| ||||0|0J| c|+a.e, !
C|||I| |JNCI|0N .t+temeat, z11
C|||I| |N||/ .t+temeat, , zz-z1, z1, 1
C|||I| |00|N .t+temeat, !, 1-1
Cre+te N+mea 9aer a|+|e |e\, !I
Cre+te New Ceaa|t|ea a|+|e |e\, +I
Cre+te New |e||c a|+|e |e\, +
C|||I| |||I|I|0N |JNCI|0N .t+temeat, z-1
C|||I| |||I|I|0N :C||M| .t+temeat, 1
C|||I| jerm|..|ea, 1zI-1z
C|||I| ||0C||J|| .t+temeat, zz1, zzI
C|||I| |0|| .t+temeat, 1z+
C|||I| :C||M| .t+temeat, z, 11-1+
C|||I| :||I||| |N||/ .t+temeat, II-I
C|||I| :\N0N\M .t+temeat,
C|||I| I|||| .t+temeat
|+.|c lerm el, I-
aec|+r+t|.e |ater|t cea.tr+|at. +aa, -!
j+rt|t|ea laact|ea. +aa .c|eme., z-1
9aer |a|ter,
.ter|a /M| aecameat., !!
C|||I| I||00|| .t+temeat,
C|||I| I\|| .t+temeat, z
C|||I| J:|| .t+temeat, 1-1I
C|||I| \||\ .t+temeat, , z-z+, z1
C|||I| /M| :C||M| C0|||CI|0N .t+temeat,
!-!
C|0:: ||||\ ejer+ter, !
C|0:: I0|N ejer+ter, I
crjter+j||c .t+temeat., 1-1
CI|., -!
CJ|| ejer+ter, !I-!
Ca|e \|t+ra, !
ca|e.
+re+t|ea, !!-!
|a+|.|. :er.|ce. +aa, !I-!II
e.er.|ew, !!-!!
j|.|c+| .ter+e el, !-!z
Ca|e. le|aer, !
cama|+t|.e +re+t|ea., !!
Carreat ||.| 9aeae |eat| ceaater, !1z
CJ|||NI_I|M|:I|M| laact|ea, !
CJ|||NI_J:|| laact|ea, !
ca.tem-|+.ea met|ea, +I+
D
-a a|a+me ejt|ea, +
||C (aea|c+tea +am|a|.tr+ter ceaaect|ea}, 1, z++
a+t+ +cce.., 11-11, !z-!1
a+t+ c|e+a|a, !!1
|+t+ ael|a|t|ea |a.tract|ea .et,
688 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
a+t+ ael|a|t|ea |+aa+e (|||}
a+t+|+.e e|ject.
C|||I| I|||| .t+temeat, I-!
a+t+|+.e., z-
aem+|a., -1
|ater|t cea.tr+|at., -1
mea|l|a, 1-z
relereat|+| |ater|t, !-
reme.|a, z-z
e.er.|ew,
.c|em+-re|+tea .t+temeat., 11-1!
.ett|a aj ..tem .ecar|t a.|a, 1-1
a+t+ aeaerm+||t+t|ea, !z
|+t+ ||recter|e. t+|, 1+
a+t+ eacrjt|ea, 1z, 1+-1
a+t+ |aaejeaaeace, !-
a+t+ |ater|t,
a+t+ m+a|ja|+t|ea |+aa+e (|M|},
a+t+ m+rt., !!1-!!+
a+t+ meae|., I
a+t+ aerm+||t+t|ea, z
a+t+ j+e.
jrejert|e. el, 11-1!
rew-e.erl|ew a+t+, 1-1
a+t+ j+rt|t|ea|a
met|ea. el, z+-z!
:9| :er.er z +aa, 1z-1+
t+||e.
ce||ec+t|a, 1-1z
l||ereaj., z-z
laact|ea., z-1
e+|., z!-z
a|ae||ae. ler, 1+
|aa|ce., 1
|e., z
aam|er el j+rt|t|ea., z
.c|eme., z-1
w|t||a w|aaew cea.tract, !1-!!
a+t+ jre.|aer., I-
a+t+ rej||c+t|ea
a|.tr||atea, +-+
m+a+|a, +I-+z
meae|., +I-+I
ja|||c+t|ea. +aa +rt|c|e., +I-+I
ja|||.|er-.a|.cr||er met+j|er, +-+
tje. el, +I-+I
|+t+ :earce \|ew |e.|aer, !I
a+t+ .earce .|ew., !-!I
|+t+ :earce \|ew. le|aer, !
|+t+ :earce \|t+ra, !
a+t+ .earce., !-!
|+t+ :earce. le|aer, !
a+t+ .tere., !!
|+t+ t+|,
a+t+ tje.
||a+r, I+-I!
||I, I+-I!
c|+r+cter, Iz
||||||C|\||, II
|0|, I!-I
aamer|c, I
.j+t|+|, I!-
:9|_\||||NI, II
temjer+|, Iz-I+
I|M|:I|M|, II-I
JN|9J||||NI|||||, I-II
\||||C|M|| lerm+t, I-I
a+t+ w+re|ea.e., !!z-!!I
||I|_I\|| ce|ama, z!
a+t+|+.e +jj||c+t|ea jrer+m., +, !-!z
||I|||:| c|+a.e, 1I
|+t+|+.e Cea.e|e Cemm+aa. (||CC} cemm+aa.,
+z-++
|+t+|+.e |a|ae
||CC cemm+aa., +z-++
a|.| .ter+e, 11-1
|a.t+ace. el, z-zI, 1I-1
|.e|+t|ea |e.e|. +aa, 1-1z
jerlerm+ace +aa, !z-!zz
.ecar|t ..tem
+at|eat|c+t|ea, 11-1
+at|er|t+t|ea, 1z-11+
a+t+|+.e .ecar|t, 1!-1
e.er.|ew, 1-11
re|e., 1-1z
.c|em+., 1z-1!
tr+c||a c|+ae., 11+-11
.|ew., 11-11
| ndex 689
..tem a+t+|+.e., 1-1z
a.|a M+a+emeat :taa|e w|t|
+am|a|.ter|a a+t+|+.e .er.er., +-+
+at|er|a +ct|.|t|e., !I-1
m+a+|a a+t+|+.e., +-!I
e.er.|ew, +
at|||t|e.
|cj, 1-+
.|cma, 1, +-+z
|+t+|+.e |a|ae Ceal|ar+t|ea j+e, 1z-1+
|+t+|+.e |a|ae Iaa|a |a.|.er, !1!-!+z
|+t+|+.e M+||, ++
a+t+|+.e m+.ter |e., 1+-1!, 1I
a+t+|+.e m|rrer|a, ++z-++1
a+t+|+.e e|ject.
cre+t|a
C|||I| I|||| .t+temeat, I-!
a+t+|+.e .a+j.|et., !-
a+t+|+.e., z-
aem+|a., -1
|ater|t cea.tr+|at., -1
relereat|+| |ater|t, !-
mea|l|a, 1-z
reme.|a, z-z
|+t+|+.e |rejert|e. a|+|e |e\, !-!1, 111-11+
|+t+|+.e |e+a-0a| ejt|ea, !z
a+t+|+.e rece.er
+atem+t|c, +z
m+aa+|, +z-+1+
meae|., +1!-+1
|+t+|+.e |e|e a|+|e |e\, 1zz, 1z!-1z
a+t+|+.e .ecar|t, I
a+t+|+.e .er.er., +z-+
|+t+|+.e :t+te ejt|ea, !z
|+t+|+.e J.er a|+|e |e\, 1I
a+t+|+.e-|e.e| tr|er., 1I
a+t+|+.ejrejert laact|ea, +1
||I|||:|||0|||I\(a+t+|+.e, jrejert} laact|ea,
||I|||:|||0|||I\|/( } laact|ea,
a+t+|+.e.. re|e., .c|em+.
+|ter|a, +-
+aterewt| jrejert el, !z
cre+t|a, z-
ae|et|a, !1
ae.|a el, -I
a|.tr||at|ea, +I
le+tare. el, +-I
m+|at+|a|a, +!-+
m+a+|a w|t| 0|ject |\j|erer, +-!I
m+.ter
e.er.|ew, 1
re.ter|a, +1+-+1!
..tem t+||e. el, z++
meae|, +, 1-1
m.a|, 1z, +1!
ejer+t|ea+|, !!
j|.|c+| ae.|a el, !-!z
re|+t|ea+|, I-, , !z-!1
rejert.er.er,
rejert.er.ertemja|,
re.earce, 1
.ecar|t, 1!-1
temja|, 1z-11, 1I, 1-1z
|+t+|+.e. le|aer, +
a+t+-ar|.ea .a|.cr|jt|ea., z
||I|||N0I|(t} laact|ea, !
||I| a+t+ tje, I1
a+te laact|ea., z
||I||||(|,a,a} laact|ea, z
||I|||||(|tem,a+t,a+tz} laact|ea, z
||I|N|M|(|tem,a+te} laact|ea, z
||I||||I(|tem,a+te} laact|ea, z
||I|I|M| a+t+ tje, I1
||I|I|M|z a+t+ tje, I1
||I|I|M|0||:|I a+t+ tje, I1
||_||(a|_a+me[} laact|ea,
||_N|M|(a|_|a[} laact|ea,
||CC (|+t+|+.e Cea.e|e Cemm+aa.} cemm+aa., +z-++
||CC C||C||||0C cemm+aa, +1
||CC C||C|C|I||00 cemm+aa, +1
||CC C||C||| cemm+aa, +1
||CC C||C|I|||| cemm+aa, +1
||CC |||||N||/ cemm+aa, z
||CC M|M0|\:I|IJ: cemm+aa, !1
||CC ||||M0N cemm+aa, !11
||CC :|0\C0NI|0 cemm+aa, z
690 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
||CC J:||0|I|0N: .t+temeat, 1z
a|e |e|a +cceaat, 1
a|e .c|em+, 1
|||. a+t+ ael|a|t|ea |+aa+e
||| .t+temeat., z-z
||| tr|er.
a+t+|+.e-|e.e|, 1I
e.er.|ew, 1I-1I
.er.er-|e.e|, 1I-1
|||||0C|_|||0||I\ ejt|ea, 1!
||C|M||(j,.[} a+t+ tje, I
aec|+r+t|.e |ater|t cea.tr+|at., -!, 1I+
|ec|+r+t|.e M+a+emeat |r+mewer| (|M|}, +-+
||C|||| .t+temeat, z
aecemje.ea .ter+e, !1-!+
|ecrjt||.m|e ..tem laact|ea, 1
|ecrjt||e ..tem laact|ea, 1
aea|c+tea +am|a|.tr+ter ceaaect|ea (||C}, 1, z++
||||J|I c|+a.e, , zz
ael+a|t a+t+|+.e .c|em+., 1z, 1
ael+a|t reaj., !++
ael+a|t |a.t+ace., z, 1
||||J|I \||J|: ejt|ea, z
||0|||:(a} laact|ea,
||||\ ejt|ea, zz
||||I| ||||0|0J| c|+a.e, !
||||I| jerm|..|ea, 1z
||||I| .t+temeat, z-z, z-z1
ae|ete_emj jreceaare, zzI
||||I|_|J|| ce|ama, z!
ae|etea t+||e., 1I
ae|et|a
+jj||c+t|ea re|e., 1zz-1z1
a+t+|+.e., !1
a.er-ael|aea a+t+|+.e re|e., 1z+
ae||m|tea |aeat|l|er.,
ae||m|ter., -I
ae||.er|a rejert.
ea-aem+aa, -z
.a|.cr|jt|ea, z-z
aem+aa j+|a, !z!
aeaerm+||t+t|ea, a+t+, !z
aeaerm+||tea a|mea.|ea t+||e., !!I
aea.e a|mea.|ea., !
||N:|_||N| laact|ea, !+-!!
||N\ .t+temeat, 1+, 11-11z
aej+rtmeat t+||e,
aejt_a+me ce|ama,
aejt_ae ce|ama, -
aer|.ea t+||e., I-
||:C ejt|ea, z1
ae.cr|jt|ea ejt|ea, +1+
|e.|a t|e 9aer j+e, -z
|e.|a t|e I+||e j+e, 1-+
aeterm|a|.t|c cemjatea ce|ama., zI+
|e.e|ejer |a|t|ea el :9| :er.er, z!
|||||||NC|(t,tz} laact|ea, 1
a|llereat|+| |+c|aj, +!
|||||||NI||| ejt|ea, +z
a|mea.|ea t+||e., !!!-!!
a|mea.|ea., ael|aea, !Iz
||mea.|ea. le|aer, !
a|rect|.e., I-
a|rt re+a, 1!
||:|||| ejt|ea, zI, 1!!
a|.+|||a |aa|ce., zI
a|.ceaaectea aer ea|t|a, !
a|.| l+||are, ++
a|.| l||e., +
a|.| |/0, !zz-!z!
||.| |e+a |te./.ec ceaater, !1z
a|.| .j+ce m+a+emeat, aa+m|c, !z
a|.| .ter+e
a+t+ j+e., 11-1
|+re a+t+|+.e., zz
j+r+||e| jrece..|a el t+.|., 1
a|.| .tr|j|a, ++
||.| \r|te |te./.ec ceaater, !1z
||.j|+ |.t|m+tea |\ecat|ea ||+a |attea, +-!
a|.j|+ea l|e|a., 1
||:I|NCI ejt|ea, 1-1z, !z-!1, z, z-zz
a|.tr||atea a+t+, +-+
||.tr||atea Ir+a.+ct|ea Ceera|a+ter (|IC}, 1+, +I
a|.tr||atea tr+a.+ct|ea., 1+, +I
||.tr||at|ea |eat, +I, +I!
a|.tr||at|ea a+t+|+.e., +I
| ndex 691
a|.tr||ater.
ceatr+| ja|||.|er w|t|, +I-+II
a+t+ rej||c+t|ea, +-+
am_a|_ c+teer, z+
am_e\ec_ c+teer, z+
am_|e_ c+teer, z+
am_tr+a_ c+teer, z+
|M| (|ec|+r+t|.e M+a+emeat |r+mewer|}, +-+
|M|. (aa+m|c m+a+emeat laact|ea.}, z++, z+-z!
|M| (a+t+ m+a|ja|+t|ea |+aa+e},
|M| .t+temeat., z-z1
|M| tr|er.
||I||, 1I-1I!
l|r.t +aa |+.t, 1I-1I
|N:I||| 0|, 1I!-1I
|M\.. aa+m|c m+a+emeat .|ew.
|e aet ae.|a +re+t|ea (} ejt|ea, !I!
aec|+||e j+ae ejt|ea, +!
|0CJM|NI |ewera,
aecameat tje ael|a|t|ea. (|I|.}, +-+
aem+|a., -1
aea||e aet+t|ea m+r|. ('},
||0| |||||C|I|0N |0|| .t+temeat, 1z1
||0| |::|M||\ .t+temeat, z1z
||0| C0|JMN c|+a.e, I
||0| |JNCI|0N .t+temeat, z+
||0| |N||/ .t+temeat, zI, !
||0| |00|N .t+temeat, 1
||0| ||0C||J|| .t+temeat, zz
||0| |0|| .t+temeat, 1z+
||0| :C||M| .t+temeat, 1!
||0| .t+temeat, z-z
||0| I|||| .t+temeat, z
||0| I||00|| .t+temeat, 1I
||0| J:|| .t+temeat, 1I
||0| \||\ .t+temeat, z+-z!
||0| /M| :C||M| C0|||CI|0N .t+temeat, !
||0|_|/|:I|N0 ejt|ea, z+, z
|IC (||.tr||atea Ir+a.+ct|ea Ceera|a+ter}, 1+, +I
|I|. (aecameat tje ael|a|t|ea.}, +-+
aar+||||t jrejert, 1+I
aa+m|c |+c|aj, +!
aa+m|c a|.| .j+ce m+a+emeat, !z
|a+m|c |e|j ejt|ea, 9aer |a|ter,
aa+m|c m+a+emeat laact|ea. (|M|.}, z++, z+-z!
aa+m|c m+a+emeat .|ew. (|M\.}
e.er.|ew, z+-z!
aer ejt|m|ter +aa, !+-!I
a.e el, z++
aa+m|c+||, ael|aea, z1

-e ejt|ea, +
-| ejt|ea, +
.|| cemm+aa, +z
ea|t|a
|aae\ |alerm+t|ea, zI-z
|aae\ea .|ew |alerm+t|ea, z-zI
.|ew |alerm+t|ea, z!-z
ea|t|ea., :9| :er.er, z1-z!
eaac+t|ea ..tem., zz
||M (|\tea.|||e |e M+a+emeat}, 1-1
|||M|NI .t+temeat, +
e|emeat., +!
|||M|NI: a|rect|.e,
||:| .t+temeat, zI
e-m+|| .a|.cr|jt|ea., z
emj_la+me ce|ama, -
emj_|a+me ce|ama, -
emj_ae ce|ama, -
emj|eee t+||e,
|a+||e ar|||aewa ejt|ea, +
|acrjt||.m|e ..tem laact|ea, 1
|acrjt||e ..tem laact|ea, 1
eacrjt|ea, 1z, 1+-1
|acrjt|ea |a+||ea ejt|ea, |+t+|+.e |rejert|e. a|+|e |e\
0jt|ea. j+e, !z
|N| .t+temeat, z
eater_a+te ce|ama, -
|aterjr|.e |a|t|ea el :9| :er.er, z!
eat|t|e., !, 1z-1zI
eat|t-re|+t|ea.||j (||} meae|, !-I, !!-!
ea|-je|a ejer+t|ea, I
|| (eat|t-re|+t|ea.||j} meae|, !-I, !!-!
|rrer +aa J.+e |ejert|a j+e, 1!-1
errer., +!I, +!-+1
692 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
|.t|m+tea .ter+e re+c|e.__M| ejt|ea, !I!
|I| (e\tr+ct|ea, tr+a.lerm+t|ea, |e+a|a}, !!1
|.+|a+te |ecemmeaa+t|ea. ejt|ea, !+z
|.+|a+te at|||t+t|ea el e\|.t|a ||: ea| ejt|ea, !1
e.eat |+aa||a, zz-zzz
|.eat \|ewer, +!
e.eat_reaj, 1I
e.eat_tje, 1I
|/C||I .et ejer+ter, 1-+
e\c|+ae ejer+ter., 1
e\c|a.|.e |ec|., 1!z-1!1
|/|CJI| |: c|+a.e, zz+
|/|CJI| jerm|..|ea, 1z
|/|CJI| .t+temeat, zz!
e\ecat|ea j|+a.
ael|aea, , , +
e\+mj|e. el, !-!+
r+j||c+|, +-!
te\ta+|, +!-+
/M|, +-+I
e\|.t( } met|ea, I-I
|/|:I: laact|ea, +I, +-!
.|/|I (.t+temeat}[ cemm+aa, +z
e\j||c|t je|a .at+\, I
|/|||C|I meae, !-
e\j||c|t tr+a.+ct|ea, 1+!
|/|(a} laact|ea,
|\jre.. |a|t|ea el :9| :er.er, z+
e\jre..|ea., +. t+||e e\jre..|ea.
|\tea.|||e |e M+a+emeat (||M}, 1-1
|\tea.|||e M+r|aj |+aa+e (/M|}
ceacejt., +1-!
aecameat.
jre.eat|a re|+t|ea+| a+t+ +., z-
retr|e.|a .terea, -z
.ter|a |a re|+t|ea+| a+t+|+.e., !z-!1
.ter|a |a :9| :er.er, !1-
e.er.|ew, +-+z, !-!z
re|+tea |+aa+e., +1
\er|a \|ae \e|, +z
/9aer met|ea., -I
|\tea.|||e :t|e.|eet |+aa+e (/:|}, +
e\teat., 1!!, 11
|/I||N|| N|M| ejt|ea, z1z
|/I||N||_|CC|:: c|+a.e, z1z
e\tr+ct|ea, tr+a.lerm+t|ea, |e+a|a (|I|}, !!1
F
l+cet., +
l+ct t+||e., !!!-!!
|+ct|ateraet:+|e. l+ct t+||e, !I+
l+||e.er c|a.ter|a, ++-++z
||:I a ||at, !1
|e+tare :e|ect|ea j+e, z-1
l||e |+c|aj, +I
l||e jrece..|a, !
l||e_.jec, 1
||||0|0J| ejt|ea, +1
l||ereaj., +-!, z-z
|||ereaj. j+e, !z
||||||0|||I\ laact|ea, z!+
||||:I|||M +ttr||ate, I!
||||||CI0| ejt|ea, z+
l||ter., +I
l|r.t aerm+| lerm (N|}, 1
l|r.t tr|er., 1I-1I
l|r.t .+|ae, 1II
l|\ea a+t+|+.e re|e., 1z-1zz
l|\ea .er.er re|e., 1-1z
l|+t .j+t|+| meae|., I!
||0|I(j}[ a+t+ tje, I
l|e+t|a j+ae ejt|ea, +!
||00|(a} laact|ea,
|0| |II|C| ejt|ea, +
|0| |II|C|_|||J|||_|00 ejt|ea, +
|0| ||I| |ewera, !I
|0| ||0|||I\ |ewera, !I
|0| \||J| |ewera, !I
|0| /M| c|+a.e, z
|0|C| 0|||| ||at, +z, !-!z
|0|C|:||| ||at, !
|0|||0N ||\ c|+a.e, +-!
|ere|a |e |e|+t|ea.||j. a|+|e |e\, !I
lere|a |e., !I
|0|M|I ejt|ea, +z
lr+meat+t|ea, z-zI
| ndex 693
||0M c|+a.e, z, z-zz, 1-1
la|| a+t+|+.e |+c|aj, +!
|J|| 0JI|| I0|N ejer+ter, I, I
la|| rece.er meae|, +1!-+1
laact|ea+| aejeaaeac|e., z
laact|ea., +-, z+!, z!1-z!+, 1
C
eaer+| |aterl+ce., z+-z!
0eaer+| j+e, +, !-!z
0eaer+| t+|, !1
eeaet|c .j+t|+| meae|., I+
0|00||||\ a+t+ tje,
0|00||||\_0||| c|+a.e, I
0|0M|I|\ a+t+ tje, I!-
0|0M|I|\_0||| c|+a.e, II-I
0et|ace.ter( } laact|ea, II
0|I|N:|NJ||('a|a+me'} laact|ea, !
0|I||I|( } laact|ea, z
0et|e.ceaa+at( } laact|ea, II
|e|+| temjer+r jreceaare., zz!
|e|+| temjer+r t+||e.,
|e|+| .+r|+||e yyerrer, 1+
|e|+| .+r|+||e yytr+aceaat, 1!
|e|+| .+r|+||e., I-
|e|+|| aa|ae |aeat|l|er. (0J||.}, I
00 .t+temeat, zz!
00I0 .t+temeat, zz
0||NI C|||I| |JNCI|0N .t+temeat, z1!
0||NI C|||I| ||0C||J|| .t+temeat, zz+
0||NI 0|I|0N |0| ejt|ea, 11z
0||NI .t+temeat, 1+, 1zI-11, 1
0r+j||c meae, !zI
r+j||c+| e\ecat|ea j|+a., -z, +-!
0|0J| |\ c|+a.e
CJ|| ejer+ter, !I-!, !1
0|0J||N0 laact|ea, !-!
0|0J||N0 :|I: ejer+ter, !-!1
|N:||I .t+temeat, z
.er.a. j+rt|t|ea|a, !1
|0||J| ejer+ter, !-!, !z
:|||CI .t+temeat, +I-+
J|||I| .t+temeat, z-zz
reaj jr|ac|j+|., 1z
0|0J||N0 laact|ea, !-!
reaj|a .er.er., ++
0|0J||N0 :|I: ejer+ter, !-!1
reaj., \|aaew., 11
ae.t .c|em+, 1
ae.t a.er +cceaat., 1zz
0J||. (|e|+|| aa|ae |aeat|l|er.}, I
H
|+ra j+e l+a|t., !z, !1
|+raw+re cr+.|e., ++
|+raw+re rea|remeat., z1
||||N||/(t,tz} laact|ea, 1
||:| ||at, !z
|+.| je|a., +1-++
|+.| j+rt|t|ea|a, z!
||\|N0 c|+a.e, !!-!
|e+j., z, +
|e|j |+.er|te. t+|, +
|e\+aec|m+| cea.t+at.,
||ae j+ae ejt|ea, +!
||er+rc||c+| eacrjt|ea |+er., 1+-1!
||er+rc||e., !Iz
||||||C|\|| a+t+ tje, II
||| +.+||+||||t, +1-+++
||.ter+m meae, !zI
||.ter+m., +
|0||| (||r|a 0|||}, !z
|0|||0C| |ec||a ||at, 1!
|er|teat+| l||ter., +I
|IM| (|jerte\t M+r|aj |+aa+e}, +z-+1
|II| (|jerte\t Ir+a.ler |retece|}, +z
||r|a 0||| (|0|||}, !z
|jerte\t M+r|aj |+aa+e (|IM|}, +z-+1
|jerte\t Ir+a.ler |retece| (|II|}, +z
I
| c||c| :tej ejt|ea, !I!
-| |ajat_l||e ejt|ea, +
||M (|aae\ +||ec+t|ea m+j} j+e., !z+
|| (|atera+| aamer|c |aeat|l|er} laact|ea, +
694 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
|| +ttr||ate, +
|aeat|l|er., -I
|||NI|I\ jrejert, , !-, z-z
|||NI|I\_|N:||I ejt|ea, !-
||||| +ttr||ate, +
|||||: +ttr||ate, +
|| .t+temeat, zI-z, 1+
|0N0||_|J|_||\ ejt|ea, z+-z!
|M|0| a+t+ tje, I
|mj||c|t je|a .at+\, I
|mj||c|t tr+a.+ct|ea, 1+!
|M|||C|I_I||N:|CI|0N: c|+a.e, 1+
|N ejer+ter, 1+-1!
|N ejt|ea, 1
|ac|aae |cta+| |\ecat|ea ||+a |attea, !
|NC|J|| ejt|ea, z1-z+
|ac|aae .a|tet+|. ejt|ea, +
|aae\ +||ec+t|ea m+j (||M} j+e., !z+
|aae\ |attea, +
|aae\ aet+|| rejert., !+
|aae\ eatr|e., z!-z!
|N||/ ||at, !-!
|aae\ j+e., z!
|N||/ aer ||at, +
|aae\ .c+a, +
|aae\ .ee|, +
|aae\ .e|ect|ea, +-+
|aae\ .t+t|.t|c., +-+
|aae\ a.+e rejert., !+
|N||/_C0| ..tem laact|ea, z!+
|N||/_C0|(t+||e, |, ae} laact|ea,
|aae\_|+aa|e ce|ama, z
|aae\ea ce|ama., +-+
|aae\ea .|ew., z1-z
|N||/||0|||I\(e|j_|a, |aae\_a+me,jrejert} laact|ea,
|aae\-re|+tea |M|., z!
|aae\-re|+tea |M\., z!
|aa|ce.
||tm+j, 1!-1
c|a.terea, z-z
cemje.|te, z1
ea cemjatea ce|ama., zI1-zI!
ce.er|a, z+, zIz-zI1
ae|etea, 1I
je|a ejer+ter +aa, zIz
aeac|a.terea, z-zz, +
e.er.|ew, z!-z
j+rt|t|ea|a, 1, 1+
.|a|e, z1
Ir+a.+ct-:9| +aa, zz-zI
|a \|||| c|+a.e, zI-zIz
|aa|.|.|||e jr|ac|j+|., 1z
|alerm+t|ea .c|em+, z+!, z!-z!
|N|0|M|I|0N_:C||M| .c|em+, 1
|alerm+t|ea_.c|em+.ce|ama. .|ew, z!
|alerm+t|ea_.c|em+.relereat|+|_cea.tr+|at. .|ew, z!
|alerm+t|ea_.c|em+.t+||e. .|ew, z!-z!
|alerm+t|.e ..tem., !!
|N|I ejt|ea, +z
|NN|| I0|N ejer+ter, I
|aaer aer|e., +z
|a-rew a+t+ j+e., 1
|N:||I jerm|..|ea, 1z
|N:||I .t+temeat
|0N0||_|J|_||\ ejt|ea, z!
|a.ert|a ma|t|j|e rew., z1-z+
|a.ert|a .|a|e rew, z-z1
|N:I||| 0| tr|er., 1I
.ter|a /M| aecameat., !!-!
t+||e .+|ae cea.tracter., z!
.|ew. +aa, zI-z
|a.ertea t+||e., 1I
|a.t+|| :||e|a w|t+ra, z
|a.t+||+t|ea Ceater, z-z
|a.t+||+t|ea |rerea|.|te. j+e, z-z
|a.t+||+t|ea |rere.. j+e, 1!-1
|a.t+|||a :9| :er.er
||C te |a.t+ace el |+t+|+.e |a|ae, 1
e.er.|ew, z-zz
j|+a ler, zz-zI
jrerea|.|te., z
:9| :er.er cemjeaeat., z-1
.t+rt|a +aa .tejj|a |a.t+ace el |+t+|+.e |a|ae, 1I
t+.|. |elere .t+rt|a :etaj jrer+m, z
|a.t+ace Ceal|ar+t|ea j+e, 1
|a.t+ace aecameat., !
| ndex 695
|a.t+ace.
el |+t+|+.e |a|ae
||C, 1
raaa|a, z-zI
.t+rt|a +aa .tejj|a, 1I
ael+a|t, z, 1
m+a+|a, +!-+
ma|t|j|e, zI
a+mea, z, 1
|N:I||| 0| tr|er., 1, 1I!-1I
|NI|0|| a+t+ tje, I
|ater|t cea.tr+|at.
+aa|a er reme.|a, -
aec|+r+t|.e, -!
aem+|a. +aa, -1
ea+|||a er a|.+|||a,
e.er.|ew,
relereat|+|, !-
||I|| tr|er., 1I+-1I!
|ate|||.ea.e tee|,
|ateat |ec|., 1!1-1!+
|aterl+ce.
eaer+|, z+-z!
jrejr|et+r, z!z-z!!
|atera+| reaj, !++
|atera+| aamer|c |aeat|l|er (||} laact|ea, +
|aterrajt./.ec ceaater, !z
|NI||:|CI .et ejer+ter, 1-+
|.|aae\+||e jrejert, z, z!
|.|aae\ea jrejert, z
|:NJ||(e\jr, .+|ae} laact|ea, !
|:NJM|||C(e\jre..|ea} laact|ea, !
|.e|+t|ea |e.e|., 1!-1z
|.e|+t|ea jrejert, 1+I
|.Jja+teaCe|ama( } met|ea, 1z
1
je| ce|ama, -
Ie| |rejert|e. a|+|e |e\, +!1, +!
je|., +!-+!
je|a ce|ama., zIz
je|a ||at., !-!1
je|a ejer+ter
C+rte.|+a jreaact, II
|aa|ce. +aa, zIz
a+tar+| je|a., I-I
eater je|a., II-
e.er.|ew, -I
.e|l-je|a., -z
.em|-je|a., z
t|et+ je|a., -
twe .at+\ lerm. te |mj|emeat je|a., I-I
je|a., !-, +z-++
k
|e-r+ae |ec|., 1
|e., eacrjt|ea, 1+-1
L
-| ejt|ea, +
.||.t cemm+aa, +z
|+re e|ject. (|0|.}, I!-I
|||0|_\||J|_I\||:_0JI_0|_|0\ ejt|ea, I!
|+.t tr|er., 1I-1I
|+.t .+|ae, 1II
|+tc|e., 1!1
|+t|taae, I+
|+er., ||er+rc||c+| eacrjt|ea, 1+-1!
|+eat t+|,
|e+.e t|e a+t+|+.e |a re+a-ea| meae ejt|ea, +1z
|e+.e t|e a+t+|+.e aea-ejer+t|ea+|, +aa ae aet re|| |+c|
aacemm|ttea tr+a.+ct|ea. ejt|ea, +1z
|e+.e t|e a+t+|+.e re+a te a.e | re|||a |+c|
aacemm|ttea tr+a.+ct|ea. ejt|ea., +1z
|||I 0JI|| I0|N ejer+ter, I, I
|||I(t, |eat|} laact|ea, 1
||N(t} laact|ea, 1
|e.e|., ael|aea, !Iz
|||| ejer+ter, 1-+z
||a|ea a|mea.|ea., !
||ter+| .+|ae., -
|0||||:I0|\ ejt|ea, +z
|0|. (|+re e|ject.}, I!-I
|ec+| temjer+r jreceaare., zz!
696 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
|ec+| temjer+r t+||e.,
|ec+| .+r|+||e., z
|ec+t|ea ce|ama,
|ec| e.c+|+t|ea, 1!!-1!
|ec| r+aa|+r|t, 1!+-1!!
|ec| meae., 1!z-1!+
|0C|_I|M|0JI ejt|ea, 1!I
|ec||a, 1!-1!
|e |||e \|ewer a|+|e |e\, +!!, +!
|e l||e., +-!
|e |e+aer |eat, +I
|e re.ter+t|ea, +z-+11
|e .eaeace aam|er. (|:N.}, 1!
|e .||jj|a, ++1-+++
|00(a} laact|ea,
|e|c+| a+t+ |aaejeaaeace, !-
|e|c+| |/0, !z+
|e|a a|+|e |e\, 1
|e|a_te.t |e|a, 1
|e|a., 11, 1, 1z
|00(a} laact|ea,
|ea|taae, I+
|00| ||at, !z
|e.t aja+te., 1!
|0\||(t} laact|ea, 1
|:N. (|e .eaeace aam|er.}, 1!
|I||M(t} laact|ea, 1
M
m+|a memer rea|remeat., z1
m+a+ea t+ret., +
M+a+emeat |+t+ \+re|ea.e (M|\}, !+z-!+1
M+a+emeat :taa|e
+aa|a a+t+|+.e a.er., 1I
+jj||c+t|ea re|e., 1z+
+..|a|a |e|a te l|\ea .er.er re|e, 1z
+..|a|a a.er te l|\ea a+t+|+.e re|e, 1zz
|+c|aj., +z-+z+
|ee|. ea||ae, +-+
ceaaect|a te .er.er, +z-++
r+j||c+| e\ecat|ea j|+a. +aa, +-!
|mj|emeat|a +at|eat|c+t|ea meae, 1+
m+a+|a |e|a. w|t|, 1
m+aa+| rece.er, +1-+11
0|ject |\j|erer, ++
er+a|t|a +aa a+.|+t|a j+ae. |a, +!-+
e.er.|ew, 1-+
jerm|..|ea., 111-11+
|e|.terea :er.er., ++
:9| :er.er jrer+m reaj, +-+
a.er-ael|aea re|e., 1z!-1z
a.|a w|t| |+t+|+.e |a|ae
+am|a|.ter|a a+t+|+.e .er.er., +-+
+at|er|a +ct|.|t|e., !I-1
m+a+|a a+t+|+.e., +-!I
e.er.|ew, +
m+a+|a |a.t+ace., +-+
m+aa+| rece.er
e.er.|ew, +z-+z
rece.er|a te m+r|, +11-+1+
||:I0|| .t+temeat., +zI-+z
re.ter|a ..tem a+t+|+.e., +1+-+1!
a.|a M+a+emeat :taa|e, +1-+11
a.|a Ir+a.+ct-:9| .t+temeat., +z-+1
m+.ter a+t+|+.e.
e.er.|ew, 1
re.ter|a, +1+-+1!
..tem t+||e. el, z++
m+tr|\ rejert., z-1,
m+\ aeree el j+r+||e||.m ejt|ea, 1
M|/ laact|ea, , !-!z
M|/ .jec|l|er, I!
M||M: (ma|t|a|mea.|ea+| a+t+|+.e ..tem.}, !!
M|\ (M+a+emeat |+t+ \+re|ea.e}, !+z-!+1
me+.are., !!
Me+.are. a|mea.|ea, !Iz
M||||||:C|||I|0N ejt|ea, +z
M||||N|M| ejt|ea, +z
M||||||::\0|| ejt|ea, +z
mem|er., 1z!, !!, !Iz
memer
mea|ter|a, !z-!1
jerlerm+ace +aa, !zz, !z!-!z
Mere |eat, +I1
| ndex 697
M||0| ||at, !z
mere je|a, +1
mere rej||c+t|ea, +I1-+I+
M||0| .t+temeat, z-z1
met+a+t+ laact|ea.,
M|cre.elt |a+|.|. :er.|ce.
|| |e.e|ejmeat :taa|e, !-!I
ca|e., !I-!II
M|cre.elt C|a.ter :er.|ce, ++z
M|cre.elt ||.tr||atea Ir+a.+ct|ea Ceera|a+ter (|IC},
1+, +I
M|cre.elt |ejert|a :er.|ce.
+cce..|a +aa ae||.er|a rejert., -z
cemjeaeat. el, -
cre+t|a rejert.
e.er.|ew, -
j+r+meter|tea, I-
w|t| |ejert :er.er |reject \|t+ra, -
m+a+|a rejert., -
jrece..|a rejert., -
M|cre.elt we| .|te, z
M|cre.elt.:9|:er.er.:er.er a+me.j+ce, 1z
M|N laact|ea, , !-!z
M|a|a :tractare. le|aer, !
m|aa. .|a (-}, +
M|||0| I0 ejt|ea, +, ++z
m|rrer|a, ++-++1
M|\ea +at|eat|c+t|ea meae, 11
m|\ea e\teat., 11
M|\ea meae, zI
M|\ea Meae r+a|e |attea, 1z
meae| a+t+|+.e., +, 1-1
meae|., rece.er, +1!-+1
meae., +at|eat|c+t|ea, zI, 11-1+
M0|||\ |||| c|+a.e, !
mea|l( } met|ea, I
mea|l_emjae jreceaare, zz
mea|l|a
ce|ama jrejert|e., I
a+t+|+.e e|ject., 1-z
l||ereaj jrejert|e., !
.tractare el |aae\ea .|ew., z!-z
M0||| (ma|t|a|mea.|ea+| 0|||}, !-!z
M0N|\ a+t+ tje, I
mea|ter|a jerlerm+ace
C|J, !z-!z
a|.| ..tem, !1-!1z
memer, !z-!1
aetwer| |aterl+ce, !1z-!11
|erlerm+ace Mea|ter e.er.|ew, !z-!z
M0\| I0 ejt|ea, zI
m.a| a+t+|+.e, 1z, +1!
m.mere_ceateat. ..tem t+||e, +I+
M::9|:||\|| .er.|ce, ++
ma|t|a|mea.|ea+| a+t+|+.e ..tem. (M||M:}, !!
ma|t|a|mea.|ea+| 0||| (M0|||}, !-!z
ma|t|j|e |a.t+ace., zI
ma|t|j|e ja|||.|er rej||c+t|ea meae|, +II-+I
ma|t|j|e rew., z1-z+
ma|t|j|e .a|.cr||er., +II-+I
ma|t|j|e-t|re+a.-jer-j+rt|t|ea .tr+te, 11
ma|t|.+|aea +ttr||ate., !
ma|t|.+|aea aejeaaeac|e., z-1
N
a+mea |a.t+ace., z, 1
N+mea ||je. aetwer| jretece|, z+
a+me.j+ce., +I
a+t|.e meae, !
a+t|.e .ter+e, !1-!+
a+tar+| je|a., I-I
NC|||(a}[ a+t+ tje, Iz
NC|||(|} laact|ea, 1
ae.tea |eej., +z-+1
Ne.tea |eej. ejer+ter, !
aet cemm+aa, 1I
aet .t+rt m..|.er.er .er.|ce, 1I
aetwer| |aterl+ce, !1z-!11
aetwer| jretece|., z1-z+
aetwer| rea|remeat., z1-z+
New |+t+|+.e a|+|e |e\, +-!
New Ie| a|+|e |e\, +!
New Ie| :c|eaa|e a|+|e |e\, +!+
New Ie| :tej a|+|e |e\, +!z
New 0jer+ter |rejert|e. a|+|e |e\, +!!
698 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
New |reject a|+|e |e\, !I, -
New |a|||c+t|ea \|t+ra, +I
New 9aer |attea, !
New :er.er 0reaj a|+|e |e\, +I
New :er.er |e|.tr+t|ea a|+|e |e\, +-+I
New :a|.cr|jt|ea \|t+ra, +
New \|ew ejt|ea, z+
N|\|| laact|ea, I-II, !
N|\:|9J|NI||||| laact|ea, I-II, !
N0 |CI|0N ejt|ea,
N0_C||C|:JM ejt|ea, +1
N0_I|JNC|I| ejt|ea, +z
aeae.( } met|ea, I
N0|/||N| ||at, !-!
N0|0|M|I ejt|ea, +z
N0|N|I ejt|ea, +z
N0|0C| |ec||a ||at, 1!
aeac|a.terea |aa|ce., z-zz, +
N0NC|J:I|||| ejt|ea, -z, z1
aeae .+|ae, 1II
aearecar.|.e aer|e., -
aeareje+t+||e re+a., 1!
aea.t+aa+ra +a+|t|c laact|ea., !I-1
N0||C0\||\ ejt|ea, +z, +z
aerm+| lerm., 1-!
aerm+||t+t|ea, z
N0:||| ejt|ea, +z
N0I ||I\||N ejer+ter, 1!-1
N0I |0| |||||C|I|0N ejt|ea, +
N0I |N jrea|c+te, !
N0I ejer+ter., 11
N0JN|0|| ejt|ea, +z
NI|z |a.t+ace, +I
NI|/I a+t+ tje, I
NI||| laact|ea, -
NJ|| .+|ae., -, 1I-1
NJ||||(e\jr,e\jrz} laact|ea, !
aam_re+a. ce|ama, !11
aam_wr|te. ce|ama, !11
aamer|c a+t+ tje, I
aamer|c laact|ea., -z
NJM|||C_|0JN|||0|I ejt|ea, z+
NJM|||C(j,.[} a+t+ tje, I
N\||C||| a+t+ tje, I!
N\||C|||(a}[ a+t+ tje, Iz
D
-e eatjat_l||e ejt|ea, +
0|ject |\j|erer
+am|a|.ter|a ma|t|j|e .er.er. w|t|, +-+
cre+t|a .|ew., z+
m+a+|a a+t+|+.e. w|t|, +-!I
0|ject |\j|erer |et+||. t+|, +!
0|ject |\j|erer j+ae, ++
0|I|CI j|+a a|ae, !+
e|ject_|a ce|ama, z
0|I|CI_||(e|j_a+me} laact|ea,
0|I|CI_N|M|(e|j_|a} laact|ea,
0|I|CI||0|||I\ laact|ea, z!+, z, 1II
e|jectjrejert jrejert laact|ea, z!
0|I|CI||0|||I\(e|j_|a,jrejert} laact|ea,
00C (0jea 0ee.j+t|+| Cea.ert|am}, I
0||| (ea||ae +a+|t|c+| jrece..|a} ..tem., !
0||| aer laact|ea., !1-!I
0|I| (ea||ae tr+a.+ct|ea jrece..|a}, z, !!-!!z,
!-!
0N c|+a.e, 1
0N ||||I| ejt|ea, -
0N J|||I| ejt|ea, -
ea-aem+aa rejert., -z
ea||ae +a+|t|c+| jrece..|a (0|||} ..tem., !
0N||N| ejt|ea, z!
ea||ae tr+a.+ct|ea jrece..|a (0|I|}, z, !!-!!z,
!-!
0jea 0ee.j+t|+| Cea.ert|am (00C}, I
0jea/M|,
ejer+t|ea+| a+t+|+.e., !!
ejer+t|ea+| t+.|., z1
ejer+ter., ++-+!, +!+-+!!
ejt|m|.t|c ceacarreac, 1+!
ejt|m|t+t|ea ||at., !I-!+
0|I|M|l| |0| ||at, !1-!+
ejt|m|ter. aer ejt|m|ter
ejt|ea_||.t, 1, +
0jt|ea. j+e, !z
| ndex 699
0| ejer+ter, 1, 1+, 1
0|||| |\ c|+a.e, !-!, !!
eraer|a, !!-!I
0|||N||_|0:|I|0N ce|ama, z!
0JI ejt|ea, 1
eater je|a., II-
eater aer|e., +z
0JI|JI ejt|ea, z-z, zz+
0\|| c|+a.e, !
ewaer.||j, .c|em+, 1z
P
-| j+..wera ejt|ea, +
j_t+||e_ejt|ea ..tem jreceaare, I
|||_|N||/ ejt|ea, z+
j+e c|+|a., z
|+e |+a|t./.ec ceaater, !1
j+e |e+aer., 1+
j+el||e...., !z!
j+e-|e.e| |ec||a, 1!z, 1!!
|+e./.ec ceaater, !1
||0|0C| |ec||a ||at, 1!
j+ae., +!-+
j+r+meter|tea rejert., I-
j+r+meter., zz+, z1I-z1, !-
j+reat t+||e., +
j+r|t, ++
j+r.|a, +I
|||I||| ejt|ea, +1
|||I|I|0N |\ c|+a.e, !1
j+rt|t|ea laact|ea., z!, z
j+rt|t|ea e+|., z!-z
j+rt|t|ea |e., z+, z
j+rt|t|ea .c|eme., z!, 1
|+rt|t|eaea +ttr||ate, 1+
j+rt|t|eaea|| ce|ama, 1z, 1+
j+rt|t|ea|a. a+t+ j+rt|t|ea|a
|+rt|t|ea. t+|, !I+
||I| meae, -I
||I|N||/(j,e\jr} laact|ea, 1
||: (||.|c+| |e.|a :tractare.}, !1
jeer-te-jeer tr+a.+ct|ea+| rej||c+t|ea, +I+-+I
|||C|NI ejt|ea, !
jerlerm+ace
l+cter. t|+t +llect, !-!z
mea|ter|a, !z-!11
tee|.
|+t+|+.e |a|ae Iaa|a |a.|.er, !1!-!+z
e.er.|ew, !11-!1+
|a :9| :er.er z, !+z-!+!
:9| :er.er |rel||er, !1+
|erlerm+ace |+t+ Ce||ecter, !+z-!+1
|erlerm+ace +|a re+c|e.__ ejt|ea, !I!
|erlerm+ace Mea|ter
C|J, !z-!z
a|.| ..tem, !1-!1z
memer, !z-!1
aetwer| |aterl+ce, !1z-!11
e.er.|ew, !z-!z
jerm|..|ea.
+jj||c+t|ea re|e., 1zz-1z1
||N\ .t+temeat, 11-11z
l|\ea .er.er re|e., 1
0||NI .t+temeat, 1zI-11
m+a+|a |a M+a+emeat :taa|e, 111-11+
ja|||c re|e, 1z
||\0|| .t+temeat, 11z-111
|erm|..|ea. j+e
|+t+|+.e |rejert|e. a|+|e |e\, !z
:er.er |rejert|e. a|+|e |e\, +
|||:|:I|| ejt|ea, zI!
jer.|.teat cemjatea ce|ama., zI+-zI!
jer.ea+| .a|.cr|jt|ea., z-z
je..|m|.t|c ceacarreac, 1++
j|+atem., 1!
j|.|c+| a+t+ |aaejeaaeace, !
j|.|c+| a+t+|+.e ae.|a, !-!z
||.|c+| |e.|a :tractare. (||:}, !1
j|.|c+| |/0, !z+
||( } laact|ea,
||\0I ejer+ter, -1
j|+a a|ae., !+
j|+a |+aa|e., !
j|+a_a|ae_|a ce|ama, !+
j|+a+r meae|., I!
je||c|e., +
700 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
|0\||(\,} laact|ea,
|re.|ew t+|, -I
|||M||\ ||\ c|+a.e, z-1
jr|m+r |e.,
|||M||\ ejt|ea, 1
jr|ac|j+| .er.er., ++z
jr|ac|j+|., 1z-1+, 1z-1zI
|||NI .t+temeat, z
jr|er|t-|+.ea re.e|at|ea, +I+
jr|.+te a|mea.|ea., !
jrec_a+me .terea jreceaare, zz+
jreceaar+| e\tea.|ea., z-zzz
jreceaare., ..tem, z!z-z!1, 1, 1z+-1z!
jrece..|a
ca|e., !I1-!I
rejert., -
|rece..er 9aeae |eat|, !z
jreaact|ea ..tem., zz
jrer+m reaj, :9| :er.er, +-+
jreject t+||e, -
jreject_aejt t+||e, !-!z
jreject_a+me ce|ama, -
jreject_ae ce|ama, -
jrejert laact|ea., z+!, z!+-z!!
jrejert reaj., a+t+|+.e, !-!z
jrejr|et+r |aterl+ce., z!z-z!!
jretece|., aetwer|, z1-z+
ja|||c |e cert|l|c+te., 1-1
ja|||c re|e, 1z
ja|||c+t|ea., +I-+I
ja|||.|er., +-+
ja|| .a|.cr|jt|ea., +I
ja.| .a|.cr|jt|ea., +I-+I

.9J|I cemm+aa, +z
9|| (aer | e\+mj|e},
aer|e.. .a|aer|e.
+a |ec, ++
+a+|.|., +
+ac|er,
c+t+|e .|ew., z+I-z+
ce.erea, z+, zIz
|aaer, +z
je|a ejer+ter
C+rte.|+a jreaact, II
a+tar+| je|a., I-I
eater je|a., II-
e.er.|ew, -I
.e|l-je|a., -z
.em|-je|a., z
t|et+ je|a., -
twe .at+\ lerm. te |mj|emeat je|a., I-I
aearecar.|.e, -
eater, +z
jerlerm+ace |eael|t. w|ea relereac|a |aae\ea
.|ew., zI-z
jrece..|a, +-+I
recar.|.e, -!
:|||CI .t+temeat
+re+te laact|ea., +-!!
C|:| e\jre..|ea., +-
C0M|JI| c|+a.e, -
0|0J| |\ c|+a.e, +I-+
||\|N0 c|+a.e, !!-!
|||NI|I\ jrejert, !-
0|||| |\ c|+a.e, !-!
e.er.|ew, z-zI
.et ejer+ter., -+
\|||| c|+a.e, zI-+z
t+||e e\jre..|ea.
CI|., -!
ael|aea, -I
aer|.ea t+||e., I-
temjer+r t+||e., -
aer | e\+mj|e (9||},
aer cemj||+t|ea, +I
9aer |a|ter, !-z
aer e\ecat|ea, +I
aer ||at., !1-!+
aer( } met|ea, I
aer ejt|m|t+t|ea,
aer ejt|m|ter
ael|aea,
laact|ea el, +I-++
| ndex 701
ejt|m|t+t|ea ||at., !I-!+
jerlerm+ace +aa, !z
j|+.e. el jrece..|a, +-+I
tee|. ler ea|t|a
|M\., !+-!I
e\ecat|ea j|+a., !-!+
M+a+emeat :taa|e, +-!
e.er.|ew, ++
:|I .t+temeat, +!-+
aer_te\t ce|ama, !+
aet+t|ea m+r|., -
aetea |aeat|l|er.,
9J0I||_|||NI||||| ejt|ea, I, z+, z
9J0I|N|M|(c|+r_.tr|a} laact|ea, 1
R
.r l||ea+me cemm+aa, +z
|||||N:(a} laact|ea,
|||| (reaaaa+at +rr+ el |ae\jea.|.e a|.|.} tec|ae|e,
++-++
|||:||||0| .t+temeat, zz, +z
||N| laact|ea,
||N0| |||I ejt|ea, z
r+ae j+rt|t|ea|a, z!
||N0| ||0|I ejt|ea, z
||N| laact|ea, !1-!!
r+a||a laact|ea., !1-!
||\ meae, 1
r+w .ter+e, !1
||| (|ejert |el|a|t|ea |+aa+e},
re+a +|e+a, !z+-!z!
|e+a ||e+a M+a+er, !z+
|||| C0MM|II|| |.e|+t|ea |e.e|, 1-1
|e+a( } laact|ea, II
|||| JNC0MM|II|| |.e|+t|ea |e.e|, 1, 1z
||||||:I |ec||a ||at, 1!
|e+a te |a.t+|| j+e, 1!
|||| a+t+ tje, I
re+|-t|me mea|ter|a, !11
|||J||| ejt|ea, z-zI
re|a||a|a |aa|ce., z
|ecemmeaa+t|ea. t+|, !+
||C0N||0J|| .t+temeat, zz
rece.er, a+t+|+.e
+atem+t|c, +z
m+aa+|, +z-+1!
meae|., +1!-+1
e.er.|ew, I
||C0\||\ ejt|ea, +z, +1I
recar.|.e mem|er,
recar.|.e aer|e., -!
reae +ct|.|t, 1!
reaaaa+at +rr+ el |ae\jea.|.e a|.|. (||||} tec|ae|e,
++-++
relereacea t+||e., +
||||||NC|: c|+a.e, +, 1z
relereac|a t+||e., +
relereat|+| |ater|t cea.tr+|at., !-
|e|.ter :er.er a|+|e |e\, +
|e|.terea :er.er. j+ae, ++
re|.ter|a .er.er., +-+I
|e|.tr+t|ea |alerm+t|ea j+e, z
re|+t|ea+| a+t+, z-
re|+t|ea+| a+t+|+.e., I-, , !z-!1
re|+t|ea+| 0||| (|0|||}, !
re|+t|ea.||j., , !I
|e|e+.e Nete., z
reme.|a
a+t+|+.e e|ject., z-z
|aa|ce., zI
.|ew., z+-z!
rea+m|a
|aa|ce., zI
.er.er., +
t+||e., !+
reaaerer., I-
||0|0|N|l| ejt|ea, z-zI
reer+a|t|a |aa|ce., z-zI
|||||I|||| |||| |.e|+t|ea |e.e|, 1
|||||C| ejt|ea, +1
|||||C|(.tr,.trz,.tr1} laact|ea, 1
|||||C|I|(t,|} laact|ea, +
rej||c+t|ea, a+t+. a+t+ rej||c+t|ea
|ejert |a||aer,
702 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
|ejert C+t+|e,
|ejert |el|a|t|ea |+aa+e (|||},
|ejert |e.|aer,
|ejert |+eat |a.tract|ea .et,
|ejert M+a+er, -I
|ejert meae, !zI
rejert jrece..er, I-
|ejert :er.er, I-
|ejert :er.er |reject \|t+ra, -
rejert .a+j.|et.,
|ejert|a :er.|ce.. M|cre.elt |ejert|a :er.|ce.
|ejert|a :er.|ce. Ceal|ar+t|ea j+e, 1+-1!
rejert.
+cce..|a +aa ae||.er|a, -z
cre+t|a
e.er.|ew, -
j+r+meter|tea, I-
w|t| |ejert :er.er |reject \|t+ra, -
m+a+|a, -
jrece..|a, -
rejert.er.er a+t+|+.e,
rejert.er.ertemja| a+t+|+.e,
reae.t |+aa|er, I-
reae.t_meae ce|ama, 1!I
reae.t_.t+ta. ce|ama, 1!I
re.er.ea |ewera., I
re.earce a+t+|+.e., 1
|e.earce 0e.eraer, !+1-!+!
re.earce_a+t+|+.e_|a ce|ama, 1!I
re.earce_tje ce|ama, 1!I
|e.tere |+t+|+.e a|+|e |e\, +1-+1z
||:I0|| ||I|||:| .t+temeat, +z, +1
||:I0|| ||||||:I0N|\ .t+temeat, +z
||:I0|| ||||||0N|\ .t+temeat, +zI-+z
||:I0|| |||||0N|\ .t+temeat, +zI
||:I0|| |00 .t+temeat, +1+
||:I0|| \||||\0N|\ .t+temeat, +z
|e.tr|ct |cce.. ejt|ea, !z
re.tr|ct|a +cce.. te a+t+, 11-11
retr|e.|a
.terea /M| aecameat., -z
.|ew., z-zI
||IJ|N .t+temeat, zz
||IJ|N: c|+a.e, z11-z1+, z1
re.er.e ea|aeer|a, !!
||\||:|(t} laact|ea, +
||\0|| .t+temeat, 11z-111
||0|I 0JI|| I0|N ejer+ter, I, I
||0|I(t,|eat|} laact|ea, +
|0||| (re|+t|ea+| 0|||}, !
re|e., 11, 1-1z
|0||||C| .t+temeat, ++
|0||||C| I||N:|CI|0N .t+temeat, 1+, 1!
|0||||C| \0|| .t+temeat, 1+
|0||J| ejer+ter, !-!
|00I a|rect|.e, -
reet a|recter, .ter|a, z
|0JN|(a, j,t[} laact|ea, z
reat|ae., z
rew ell.et t+||e., 1!
rew .er.|ea|a, 1z-1+
|0\_NJM||| laact|ea, !+-!!
|0\C0JNI_||0 laact|ea, z
|0\0J||C0| |ewera, II
|0\0J||C0| jrejert, +I1-+I+
rew-|e.e| |ec||a, 1!+-1!!, !z
|0\|0C| |ec||a ||at, 1!
rew-e.erl|ew a+t+, 1-1
rew., |a.ert|a, z-z+
|0\\||:|0N ce|ama, II-I, z
|I||M(t} laact|ea, +
|aa New a|+|e |e\, +
S
-: .er.er_a+me\|a.t+ace_a+me[ ejt|ea, +
.+ |e|a, 1z
.+mj|e a+t+|+.e, -
:|\| I||N:|CI|0N .t+temeat, 1+-1+
.+.eje|at., 1+
.c+|+r laact|ea., -
.c+|+r ejer+ter., I-
.c|em+ .+||a aecameat., !
.c|em+_a+me, zz+, 1
:C||M|||N||N0 c|+a.e, z1+, z, z1
:C||M|||N||N0 ejt|ea, z!-z
| ndex 703
.c|em+.
cac, 11
ael+a|t a+t+|+.e, 1z, 1
ael|aea, !,
|alerm+t|ea, z+!, z!-z!
.ecar|t ..tem el |+t+|+.e |a|ae, 1z-1!
.aewl|+|e, !!I
.t+r, !!!-!!
.., z+, 1
.e+rc| +rameat., +I
:e+rc| |attea, +-+
.e+rc|ea C|:| e\jre..|ea, !
.eceaa aerm+| lerm (zN|}, 1-+
.ecar+||e., 1+, 1zI-1z, 11
.ecar|t, a+t+|+.e, I
:ecar|t j+e, +
.eea.,
:|||CI jerm|..|ea, 1z-1z
:e|ect ||+a |rejert|e. w|t+ra j+e, +
:e|ect |ejert 0jt|ea. w|t+ra j+e, +
:|||CI .t+temeat
+re+te laact|ea., +-!!
C|:| e\jre..|ea., +-
ce|ama a+me., I+
C0M|JI| c|+a.e, -
0|0J| |\ c|+a.e, +I-+
||\|N0 c|+a.e, !!-!
|||NI|I\ jrejert, !-
0|||| |\ c|+a.e, !-!
e.er.|ew, z-zI
.et ejer+ter., -+
t+||e e\jre..|ea.,
t+||e., I!
a.|a te ceateat el \m|t+| t+||e, !
\|||| c|+a.e
|ee|e+a ejer+ter., 1-1+
|||| ejer+ter, 1-+z
NJ|| .+|ae. +aa, 1I-1
|N ejer+ter, 1+-1!
||I\||N ejer+ter, 1!-1I
e.er.|ew, zI-1
:e|ect t|e |+t+ :earce j+e,
:e|ect t|e |ejert Ije j+e, z-1
.e|ect_.t+temeat, z
.e|ect|.|t
ceaa|t|ea, zI
e\jre..|ea, +
.e|l-ceat+|aea .a|aer|e., +1
.e|l-je|a., -z
.em|-je|a., z
:||||||l|||| |.e|+t|ea |e.e|, 1-1z
:er.er Ceal|ar+t|ea j+e, 1z
:er.er N+me l|e|a, +z
:er.er |rel||er, !1+
:er.er |rejert|e. a|+|e |e\, +-+
:er.er |e|e |rejert|e. a|+|e |e\, 1z
:er.er Ije l|e|a, +z
.er.er-|e.e| tr|er., 1I-1
:||\||||0|||I\(jrejerta+me} laact|ea, !
.er.er., +z-+
.er.|ce m+.ter |e., 1+
.e..|eajrejert jrejert laact|ea, z
:et |re+t|ea 0jt|ea. j+e, !I!
:|I ||I||0|M|I .t+temeat, I1
:|I ||||J|I ejt|ea,
:|I NJ|| ejt|ea,
.et ejer+ter., -+
:|I .t+temeat, , +!-+I
:etaj jrer+m, z
:0M| (:t+aa+ra 0eaer+| M+r|aj |+aa+e}, +1
.|+rea a|mea.|ea., !
.|+rea |ec|., 1!z-1!1
.|+rea memer aetwer| jretece|, z+
:|+reje|at |ater+tea meae, !
:|ew aet+||. |attea, z-z
:|0\|||N_||| ejt|ea, +!
:|0\|||N_I|/I ejt|ea, +!
:|0\|||N_/M| ejt|ea, +I
:|0N(a} laact|ea, z
.|mj|e C|:| e\jre..|ea, !
.|mj|e rece.er meae|, +1I
.|a|e |aa|ce., z1
.|a|e aet+t|ea m+r|. ('},
.|a|e rew., |a.ert|a, z-z1
.|a|e-|te c|+r+cter., Iz
.|a|e-t|re+a-jer-j+rt|t|ea .tr+te, 11
704 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
:|N(a} laact|ea, z
:||| ejt|ea, +z
:M|||||I|I|M| a+t+ tje, I1
:M||||NI a+t+ tje, I
:M|||M0N|\ a+t+ tje, I
:a+j.|et |eat, +Iz
.a+j.|et rej||c+t|ea, +Iz-+I1
.aewl|+|e .c|em+., !!I
.elt j+e l+a|t., !z, !1
:e|at|ea |\j|erer, z-1
:e|at|ea |\j|erer j+ae, !
:0|I_|N_I|M||| ejt|ea, z+-z!
:0JN||/(+} laact|ea, +
.earce t+||e., 11-11I
.j_+aame..+e .terea jreceaare, +z
.j_+aaja|||c+t|ea ..tem jreceaare, +I!
.j_+aare|emem|er ..tem jreceaare, 1z!
.j_+aaamjae.|ce ..tem jreceaare, +!1
.j_ceal|are_jeerceal||ctaetect|ea ..tem jreceaare, +I!
.j_ceatre|_j|+a_a|ae ..tem jreceaare, !+
.j_cre+te_j|+a_a|ae ..tem jreceaare, !+
.j_cre+te.t+t. ..tem jreceaare, +
.j_a|_.+raec|m+|_.ter+e_lerm+t ..tem jreceaare, I
.j_a|ejt|ea ..tem jreceaare,
.j_ael+a|ta| ..tem jreceaare, !
.j_aejeaa. ..tem jreceaare, z!z-z!1
.j_aet+c|_a| ..tem jreceaare,
.j_arejre|emem|er ..tem jreceaare, 1z!
.j_|e|j ..tem jreceaare, z!z
.j_|e|j|aae\ ..tem jreceaare, z
.j_|e|jre|e ..tem jreceaare, 1z!
.j_|e|jte\t ..tem jreceaare, z!
.j_|ec| ..tem jreceaare, 1!I
.j_mea|ter ..tem jreceaare, !z, !1z
.j_rea+me .terea jreceaare, +
.j_rea+me ..tem jreceaare, , zI
.j_.et+jjre|e ..tem jreceaare, 1z1
.j_.ettr|ereraer ..tem .terea jreceaare, 1I
.j_.j+cea.ea ..tem jreceaare, z
.j_t+||eejt|ea ..tem jreceaare, I!-I
.j_\m|_jrej+reaecameat ..tem jreceaare, -
.j_\m|_reme.eaecameat ..tem jreceaare,
:||C|(|eat|} laact|ea, +
.j+r.e a|mea.|ea., !
.j+t|+| a+t+, I1-
.j|ere|a., I+
.j|a|ec|., 1!1
:9| (:tractarea 9aer |+aa+e},
:9| ejt|ea.,
:9| j|+a a|ae, !+
:9| :er.er z
cemjeaeat.
+atem+t|ea, ++
cemmeat., I
a+t+ tje., I-I
ae||m|ter., -I
|aeat|l|er., I
|a.t+|||a, z-1
||ter+| .+|ae., -
NJ|| .+|ae., -
re.er.ea |ewera., I
.c+|+r ejer+ter., I-
Ir+a.+ct-:9| laact|ea., I-
a+t+ j+rt|t|ea|a +aa, 1z-1+
ea|t|ea., z+-z!
eacrjt|ea ea|+acemeat., 1-1
|erlerm+ace |+t+ Ce||ecter, !+z-!+1
jrer+m reaj, +-+
|e.earce 0e.eraer, !+1-!+!
.ecar|t .a|..tem, 11
.ter|a /M| aecameat. |a, !1-
:9| :er.er |eat errer |e, +!
:9| :er.er |at|eat|c+t|ea, +1
:9| :er.er |ee|. 0a||ae (|0|}, +-+
:9| :er.er |a.t+||+t|ea Ceater, z-z
:9| :er.er M+a+emeat :taa|e. M+a+emeat :taa|e
:9| :er.er |rel||er, !1+
.|_|+aa|e ce|ama, !z
:9|_\||||NI a+t+ tje, II
.|cma at|||t, 1, +-+z
:9|Cemm+aa c|+.., 1z
:9|Ceaaect|ea c|+.., 1z
:9|/0|||, !-!
:|||je c|+.., 1+
.|.er.r +jj||c+t|ea, 1I
:9|I(a} laact|ea, z
| ndex 705
:9J|||(a} laact|ea, z
:t+aa+ra |a|t|ea el :9| :er.er, z!
:t+aa+ra 0eaer+| M+r|aj |+aa+e (:0M|}, +1
:I|N||\ ejt|ea, +z, +z-+1
.t+aa| .er.er., +1-++
.t+r .c|em+ aer ejt|m|t+t|ea, 1+-1
.t+r .c|em+., !!!-!!
:t+te ejt|ea., !z,
.t+t|c |+c|aj, +!
.t+t|.t|c+| +re+te laact|ea., !!, !-!I
.t+t|.t|c., +, +-+
:I|I|:I|C: |0 ejt|ea, +
:I|I|:I|C: ||0|||| ejt|ea, +
:I|I|:I|C: I|M| ejt|ea, +
:I|I|:I|C: /M| ejt|ea, +I
:I|I|:I|C:_N0||C0M|JI| ejt|ea, z!
:I|I: ejt|ea, +z
.t+ta. |+r, !-
:ICeat+|a.( } met|ea, I
:I||\ +re+te laact|ea, !!, !
:I||\| +re+te laact|ea, !!, !
:tejjea ejt|ea, +
:I0eem|remIe\t( } met|ea, I
:I|ater.ect.( } met|ea,
:I|eat|( } met|ea,
:I||ae|remIe\t( } met|ea, II
:I0||I ejt|ea, +1
:I0||IM||| ejt|ea, +1, +1+
:I0||||0||M||| ejt|ea, +1, +1+
.terea jreceaare.
C|| +aa, zz-z11
cre+t|ea +aa e\ecat|ea el, zz1-zz
ael|aea,
e.er.|ew, zzz-zz1
jreceaar+| e\tea.|ea., z-zzz
.ter|a
reet a|recter, z
/M| aecameat.
|a re|+t|ea+| a+t+|+.e., !z-!1
retr|e.|a, -z
|a :9| :er.er, !1-
:I|e|at|remIe\t( } met|ea, II
:I|e||remIe\t( } met|ea, II
:I|(l,|ea ,a[[} laact|ea, +
.tr|a cea.t+at.,
.tr|a laact|ea., 1-+
:tractarea 9aer |+aa+e (:9|},
:IJ||(t,+,|eat|,tz} laact|ea, +
.a|aer|e., +z-+I, 1-
.a|.cr||er., +-+
.a|.cr|jt|ea.
a+t+ rej||c+t|ea, +I
e-m+||, z
rejert, z-z
:J|:I||N0(t,+,|eat|} laact|ea, +
:JM +re+te laact|ea, !z-!1
:JM laact|ea,
.mmetr|c |e eacrjt|ea, 1!-1
.aeam., ael|aea,
.at+\ ||||||t|a,
.. .c|em+, z+, 1
...+||_e|ject. c+t+|e .|ew, z+-z+I
...a+t+|+.e_jerm|..|ea. c+t+|e .|ew, 111
...a+t+|+.e_jr|ac|j+|. c+t+|e .|ew, z+, 1
...a+t+|+.e. c+t+|e .|ew, +1
...am_a|_|aae\_j|.|c+|_.t+t. |M\, z-zI
...am_a|_|aae\_a.+e_.t+t. |M\, z
...am_a|_m|..|a_|aae\_aet+||. |M\, z
...am_e\ec_ceaaect|ea. .|ew, !11
...am_e\ec_jreceaare_.t+t. |M\, !-!I
...am_e\ec_aer_ejt|m|ter_|ale |M\, !+-!!
...am_e\ec_aer_j|+a |M\, !!-!
...am_e\ec_aer_.t+t. |M\, !
...am_e\ec_reae.t. .|ew, !z
...am_e\ec_.e..|ea. |M\, z
...am_e\ec_.e..|ea. .|ew, 1
...am_e\ec_.|_te\t |M\, !
...am_e\ec_te\t_aer_j|+a |M\, !
...am_e._memer_c|er|. .|ew, !1
...am_e._memer_e|ject. .|ew, !1
...am_e._w+|t_.t+t. .|ew, !1z
...am_tr+a_|ec|. aa+m|c m+a+emeat .|ew, 1!I
...|aae\_ce|ama. c+t+|e .|ew, zI
...|aae\e. c+t+|e .|ew, zI
...e|ject. c+t+|e .|ew, zz, z+-z+I, z!, 1
...j|+a_a|ae. c+t+|e .|ew, !+
706 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
...jreceaare. c+t+|e .|ew, zz
....j_cac_ea+||e_a|_c|+ae_a+t+_c+jtare .terea
jreceaare, 11
....j_cac_ea+||e_t+||e_c|+ae_a+t+_c+jtare .terea
jreceaare, 11
....j_e.t|m+tea_rew.|te_reaact|ea_ler_.+raec|m+|
.|ew, I
....j+t|+| |aae\e. .|ew, I
....j+t|+|_|aae\_te..e||+t|ea. .|ew, I
....t+t. .|ew, +
....t+t._ce|ama. .|ew, +
.....jrece..e. c+t+|e .|ew, !z
.....tem_e|ject. c+t+|e .|ew, z+-z+I
..tem +am|a|.tr+t|ea t+.|., +atem+t|a
+|ert., +!I-+1
je|., +!-+!
ejer+ter., +!+-+!!
:9| :er.er |eat, ++
..tem +am|a|.tr+ter., 1z
..tem |+.e t+||e., z++
..tem c+t+|e
eaer+| |aterl+ce., z+-z!
e.er.|ew, z++-z+
jrejr|et+r |aterl+ce., z!z-z!!
:.tem Ceal|ar+t|ea C|ec| j+e, z-1
..tem a+t+|+.e.
m+.ter
e.er.|ew, 1
re.ter|a, +1+-+1!
..tem t+||e. el, z++
meae|, +, 1-1
m.a|, 1z, +1!
e.er.|ew, z
re.ter|a, +1!
temja|, 1z-11, 1I, 1-1z
..tem errer., +!I, +!-+1
..tem laact|ea., +-, z+!, z!1-z!+, 1
..tem jreceaare., z!z-z!1, 1, 1z+-1z!
:.tem | jreject,
..tem re.earce.
a|.| |/0, !z1-!z!
memer, !z!-!z
e.er.|ew, !zz-!z
re+a +|e+a, !z+-!z!
:\:I|M_J:|| laact|ea, !
:.tem.|+t+.:|C||eat a+me.j+ce, 1z
...\m|_.c|em+_+ttr||ate. .|ew,
...\m|_.c|em+_cemjeaeat. .|ew,
...\m|_.c|em+_e|emeat. .|ew,
7
-I ejt|ea, +
-t .eceaa. ejt|ea, +
t+|_a+me t+||e, z
t+||ea aecameat ejt|ea, +!
I+||e +cce.. rejert, !+
I|||| a+t+ tje, z1-z1I
t+||e e\jre..|ea.
cemmea (CI|.}, -!
ael|aea, -I
aer|.ea t+||e., I-
t+||e ||at., !-!
I|||| ejt|ea, 1!!
I+||e |rejert|e. a|+|e |e\, !+-!!, 111, 11!
t+||e .c+a/a|met|ea, z!
t+||e .+|ae cea.tracter., z!
I||||_C|I||00 ce|ama, z!-z!
t+||e_a+me, 1
I||||_N|M| ce|ama, z!-z!
I||||_:C||M| ce|ama, z!-z!
I||||_I\|| ce|ama, z!
t+||e-|e.e| cea.tr+|at.,
t+||e-|e.e| |ec||a, 1!!
t+||e.
+|ter|a, -z
c|a.terea, z-z
ce||ec+t|a, 1-1z
||||I| .t+temeat, z-z
aeaerm+||tea a|mea.|ea, !!I
aer|.ea, I-
a|mea.|ea, !!!-!!
l+ct, !!!-!!
|N:||I .t+temeat, z-z!
|a.ertea, 1I
| ndex 707
je|a|a mere t|+a twe, I!-I
m+a+|a w|t|eat Ir+a.+ct-:9|, !1-!I
M||0| .t+temeat, z-z1
0JI|JI c|+a.e, z-z
e.er.|ew, I
j+reat, +
j+rt|t|ea|a, z!-1z
relereac|a, +
re|+t|ea.||j., !I
rea+m|a, !+
rew ell.et, 1!
.earce, 11-11I
..tem |+.e, z++
temjer+r, , -
J|||I| .t+temeat, z!-zI
.|rta+|,
I+||e. +aa Ce|ama. a|+|e |e\, !I
t+||e-.+|aea laact|ea., !, z1-z+
t+||e-.+|aea j+r+meter., z1I-z1
I|||0C| (I|||0C|/} |ec||a ||at, 1!
t+|a|+r rejert., z-1
t+ a+me., +!
I||| 0\N||:||| jerm|..|ea, 1z
I|N(a} laact|ea, z
t+je |+c|aj ae.|ce., +
t+ret .et., +
IC|/|| aetwer| jretece|, z+
I|| (Ir+a.j+reat |+t+ |acrjt|ea}, 1
temja| a+t+|+.e, 1z-11, 1I, 1-1z
I|M|||I| j|+a a|ae, !+
temjer+| a+t+ tje., Iz-I+, 1
temjer+r t+||e., , -
I|/I a+t+ tje, I
I|/I_|N_|0\ ejt|ea, I
te\t/|m+e a+t+ tje., I
te\ta+| e\ecat|ea j|+a., +!-+
t|et+ je|a., -
t||ra aerm+| lerm (1N|}, +-!
I|M| a+t+ tje, I1
I|M| ejt|ea, zz
I|M|0JI ejt|ea, zz
I|M|:I|M| a+t+ tje, II-I, z
I|N\|NI a+t+ tje, I
tee||+r, !
I0| c|+a.e, !I-
Ie:tr|a( } met|ea,
tr+ce l|+ z++, 11
tr+c||a c|+ae., 1z, 11+-11
I||N:|CI|0N |:0||I|0N ||\|| ejt|ea, 1z
tr+a.+ct|ea |e |+c|aj, +!-+I
tr+a.+ct|ea .eaeace aam|er (/:N}, 1z-11
tr+a.+ct|ea_a+me, 1+I
tr+a.+ct|ea+| rej||c+t|ea, +I-+Iz
tr+a.+ct|ea-re|+tea |M|., z!
tr+a.+ct|ea-re|+tea |M\., z!
tr+a.+ct|ea., 1+!-1!
Ir+a.+ct-:9| laact|ea., I-
Ir+a.+ct-:9| |+aa+e
+aa|a a+t+|+.e a.er., 1-1I
+jj||c+t|ea re|e., 1zz-1z1
+.mmetr|c |e., 1
+at|er|t+t|ea, 1z-111
|| +aa
0|0J| |\ c|+a.e e\tea.|ea., !I-!1
aea.t+aa+ra +a+|t|c laact|ea., !I-1
0||| aer laact|ea., !1-!I
:9|/0|||, !-!
w|aaew cea.tract, !-!I
cert|l|c+te., 1I-1
cre+t|a a+t+|+.e. w|t|eat, +-!z
|\tea.|||e |e M+a+emeat, 1
|aa|ce. +aa, zz-zI
m+a+|a t+||e. w|t|eat, !1-!I
mea|l|a a+t+|+.e. w|t|eat, !z-!1
e.er.|ew,
.c|em+., 11-1!
.ett|a aj ..tem .ecar|t, 1-1
.mmetr|c |e., 1
a.er-ael|aea a+t+|+.e re|e., 1z+
.|ew., 11
Ir+a.+ct-:9| .t+temeat.
|+c|aj., +-+z
m+aa+| rece.er, +z-+1
tr+a.+ct|ea. +aa, 1+I-1!
Ir+a.j+reat |+t+ |acrjt|ea (I||}, 1
tree ||er+rc|, ++
708 Mi c r os of t S QL S er v er 2 00 8: A 8egi nner ' s Gui de
tr|er.
C|| +aa, 1-1!
|||, 1I-1
ael|aea,
|M|
||I||, 1I-1I!
cre+t|a, 1-1
l|r.t +aa |+.t, 1I-1I
|N:I||| 0|, 1I!-1I
mea|l|a .tractare, 1-1I
e.er.|ew, 1
rej||c+t|ea, +
tr+c||a c|+ae. w|t|, 11!
a.|a ae|etea +aa |a.ertea t+||e., 1I
tr|.|+| laact|ea+| aejeaaeac|e., z
tr|.|+| j|+a ejt|m|t+t|ea, +I
I|JNC|I| I|||| .t+temeat, z-z
tra.tea ceaaect|ea., 11, +
I|\ .t+temeat, zz-zzz, 1+
I|\/C|IC| ||ec|., +z
Iaa|a 0jt|ea. t+|, !1
twe-j|+.e cemm|t met|ea, +I
I\|| a|rect|.e, I-
I\||||0|||I\ laact|ea, z!!
U
-J |e|a_|a ejt|ea, +
J||.. a.er-ael|aea laact|ea.
aa+r +r|t|met|c ejer+ter., I
aaae +ct|.|t, 1!
Ja|ceae c|+r+cter., Iz
JN|C0|| laact|ea, +
aa|lerm e\teat., 11
aa|lerm re.earce |aeat|l|er. (J||.}, +I
JN|0N .et ejer+ter, -1
JN|9J| ejt|ea, -z, z1
JN|9J||||NI||||| a+t+ tje, I-II, +I1-+I+
JN|0|| ejt|ea, +z
JN||\0I ejer+ter, -1
aja+te |ec|., 1!z-1!1
J|||I| jerm|..|ea, 1z-1z
J|||I| .t+temeat, z!-zI, z-z, 1I
J|||I|_|J|| ce|ama, z!
aja+te., ceacarreac, 11!
J|||0C| |ec||a ||at, 1!
J||||(t} laact|ea, +
J||. (aa|lerm re.earce |aeat|l|er.}, +I
J:| .t+temeat, !
a.er +cceaat., 11, 1-1I
a.er |aterl+ce., !
a.er |e., 1!-1
a.er_cre+tea ce|ama, +
J:||_||(a.er_a+me[} laact|ea, !
J:||_N|M|(|a[} laact|ea, !
a.er-ael|aea +re+te laact|ea., !!
a.er-ael|aea a+t+|+.e re|e., 1z+-1z
a.er-ael|aea errer., +-+1
a.er-ael|aea laact|ea. (J||.}
C|| +aa, z+-z+
cre+t|ea +aa e\ecat|ea el, z11-z+
jreceaar+| e\tea.|ea., z-zzz
a.er., 1z, 1zz
at|||t|e.
|cj, 1-+
.|cma, 1, +-+z
V
.+||a+t|ea cemm+aa., +1-++
\||J| c|+a.e, z1
.+|ae( } met|ea, I
\|| +re+te laact|ea, !!, !
\||||N||\ a+t+ tje, I+-I!
\||C||| a+t+ tje, I!
\||C|||(a}[ a+t+ tje, Iz
\||||C|M|| lerm+t, I-I
.+r|+||e.
|e|+|, I-
|ec+|, z
tjea /M|, !-
\||| +re+te laact|ea, !!, !
.ert|c+| l||ter., +I
\|| (\|rta+| |aterl+ce |a+jter} aetwer| jretece|, z+
\||\ ||||N|I|0N jerm|..|ea, 1z-11
\||\ :||\|| :I|I| jerm|..|ea, 1
| ndex 709
\||\_M|I|||I| ejt|ea, z
.|ew_a+me, z, 1
.|ew.
c+t+|e
eacrjt|ea, 1
e.er.|ew, z++, z+
jerm|..|ea., 111
aer|a, z+I-z+
/M| :c|em+,
cemj+t|||||t, z+I
a+t+ .ecar|t, 11-11
a+t+ .earce, !-!I
||| .t+temeat. +aa, z-z
ael|aea,
aer|.|a lrem e\|.t|a, z1-z+
|M| .t+temeat. +aa, z-z1
aa+m|c m+a+emeat (|M\.}
e.er.|ew, z+-z!
+aa aer ejt|m|ter, !+-!I
a.e el, z++
eacrjt|ea c+t+|e, 1
|aae\ea, z1-z
.|rta+| cemjatea ce|ama., zI+
\|rta+| |aterl+ce |a+jter (\||} aetwer| jretece|, z+
.|rta+| t+||e., . .|ew.
W
w+|t_tje ce|ama, !1z
\||I|0| .t+temeat, zz
w+|t|a_t+.|._ceaat ce|ama, !1z
w+re|ea.e., a+t+, !!z-!!I
we| |rew.er., +z
we| .er.er, +z
we| .|te, M|cre.elt, z
\e||-|aewa Ie\t (\|I} rejre.eat+t|ea, I-II
\|||| c|+a.e
|ee|e+a ejer+ter., 1-1+
|aa|ce. |a, zI-zIz
|||| ejer+ter, 1-+z
NJ|| .+|ae. +aa, 1I-1
|N ejer+ter, 1+-1!
||I\||N ejer+ter, 1!-1I
e.er.|ew, zI-+z
J|||I| .t+temeat, z!
\|||| .t+temeat, z-z, 1+
w||ac+ra c|+r+cter., 1
w|aaew cea.tract, !-!I, 1
\|aaew. +jj||c+t|ea |e, +!
\|aaew. |at|eat|c+t|ea meae, zI, +1, 11
\|aaew. +at|eat|c+t|ea meae r+a|e |attea, 1z
\|N|0\: c|+a.e, 1
\|aaew. |.eat \|ewer, +!
\|I| C||C| ejt|ea,
\|I| C||C| 0|I|0N ejt|ea, zI-z
\|I| |NC|\|I|0N ejt|ea, z1+, z
\|I| 0||NI 0|I|0N c|+a.e, 11-11
\|I| M||| c|+a.e, +1+
\|I| N0C||C| ejt|ea,
\|I| |||M|::|0N :|I c|+a.e, z1z
\|I| ||C0M|||| ejt|ea, zz+
\|I| :C||M|||N||N0 c|+a.e, z1+
\|I| .t+temeat,
\|I| I||: ejt|ea, !
w|t|_c|ec|_ejt|ea ce|ama, z!
\|I (\e||-|aewa Ie\t} rejre.eat+t|ea, I-II
\er|reaj |a|t|ea el :9| :er.er, z!
\er||e+a +a+|.|. rejert, !+
wer|._ea t+||e, -
\r|te( } laact|ea, II
X
/|0C| |ec||a ||at, 1!
/M|. |\tea.|||e M+r|aj |+aa+e
/M| a+t+ tje, !+-
/M| e\ecat|ea j|+a., +-+I
/M| :c|em+ |el|a|t|ea |+aa+e (/:|}, !, !-
\m|a. +ttr||ate, +I
/|+t| aer |+aa+e,
/9aer |+aa+e,
/9aer met|ea., -I
/:| (/M| :c|em+ |el|a|t|ea |+aa+e}, !, !-
/:|N|| ejt|ea,
/:| (|\tea.|||e :t|e.|eet |+aa+e}, +
/:N (tr+a.+ct|ea .eaeace aam|er}, 1z-11