You are on page 1of 21

Implementing the Physical Database

Date: Nov 11, 2005 By Thomas Moore, Ed Tittel. Sample Chapter is provided co rtesy o! " e. This chapter deals #ith the physical compo$e$ts o! a S"% Server data&ase system. Be'i$$i$' #ith the server hard#are, or'a$i(i$' the data stora'e a$d creati$' the physical !iles is #here a lot o! ! t re per!orma$ce #ill &e determi$ed. Terms you'll need to understand:

)*+D ,i'a&it Data&ase Ta&le )ecord )o# Col m$ -ield -ile'ro ps Cl stered i$de. No$cl stered i$de. Tri''er /rimary 0ey -orei'$ 0ey Co$strai$t Stored proced re %o' !ile Model data&ase

Techniques you'll need to master:

1ard#are set p2!ile placeme$t Data&ase creatio$ 3&4ect creatio$ Setti$'2alteri$' properties Setti$' co$strai$ts

Introduction This chapter deals #ith the physical compo$e$ts o! a S"% Server data&ase system. Be'i$$i$' #ith the server hard#are, or'a$i(i$' the data stora'e a$d creati$' the physical !iles is #here a lot o! ! t re per!orma$ce #ill &e determi$ed. There are ma$y optio$s to

co$sider !or a prod ctio$ e$viro$me$t, a$d o$e thi$' is certai$: The mi$im m i$stallatio$ re5 ireme$ts #ill $ot &e s !!icie$t. The comp ter hard#are compo$e$ts are o$ly the &e'i$$i$' o! the physical eleme$ts. *ltho 'h #e te$d to thi$0 o! the physical realm as thi$'s that #e ca$ to ch a$d !eel, #ithi$ a DBMS e$viro$me$t it also de!i$es the compo$e$ts o! the data&ase itsel!. The data&ase layo t, the 0ey str ct res, co$strai$ts, a$d other so!t#are eleme$ts are all co$sidered physical eleme$ts. +t6s time !or the e$tities disc ssed i$ the lo'ical desi'$ to &ecome ta&les. +$ a$y physical desi'$, the 'oal is to provide a$ e!!icie$t a$d respo$sive data&ase system that also le$ds itsel! to appropriate mai$te$a$ce tas0s #itho t &ecomi$' a data&ase admi$istrator6s & rde$. *t this sta'e o! a data&ase impleme$tatio$, care is ta0e$ to provide a system str ct re that is sa&le, provides !or optim m ser respo$se time, ca$ &e readily mai$tai$ed, a$d a&ove all meets the $eeds o! the & si$ess !or #hich it #as desi'$ed. +$ movi$' !rom a$ idea to a lo'ical str ct re to the act al physical eleme$ts, yo m st remem&er to co$sider eleme$ts that co$tri& te to per!orma$ce, relia&ility, a$d data i$te'rity. 1avi$' a model o! the system is o$e thi$', & t it m st &e a&le to meet the dema$ds o! a$ e$viro$me$t i$ #hich i$evita&ly the system m st meet the i$te$ded 'oals o! the compa$y a$d add to the &ottom li$e. +$ a &oo0 o! this $at re, tryi$' to !it all topics i$to the !ray i$ a lo'ical ma$$er ca$ sometimes &e a#0#ard. +$ this chapter #e #ill disc ss some o! the hard#are impleme$tatio$s that pro&a&ly sho ld #ait !or a data&ase desi'$ a$d other criteria. 7e #ill approach the hard#are $e.t !rom a sta$dpoi$t o! #hat the &aseli$e r les are !or esta&lishi$' the server. A Hardware Dialogue +$ a prod ctio$ e$viro$me$t, & d'et is 'oi$' to limit some o! the hard#are decisio$s &ei$' made. 3!te$, $e# hard#are is$6t eve$ co$sidered, tho 'h i$ ma$y cases it is $eeded. %et s approach the topic !irst !rom a mi$im m hard#are perspective a$d the$ pro'ress to a s al or &est8practice sce$ario. -i$ally, #e #ill loo0 at the optim m hard#are9the hard#are #e #o ld choose i! there #ere a very lar'e & d'et availa&le to cover e5 ipme$t costs. %et6s start #ith somethi$' that may &e !o $d o$ the *dmi$istratio$ e.am, tho 'h less li0ely see$ #ithi$ the desi'$ topics. These are the mi$im m re5 ireme$ts as speci!ied &y Microso!t:

/e$ti m 1::M1( or hi'her :;MB mi$im m, 12<MB or more recomme$ded S"% Server data&ase compo$e$ts: =5MB>2?0MB, 250MB typical @,* or hi'her resol tio$ CD8)3M drive

No# i! + #ere to #al0 i$to a$ o!!ice a$d see this system as my prod ctio$ machi$e, + #o ld li0ely immediately t r$ a$d r $ a#ay. Eve$ as a test system, this #o ld &e a !ri'hte$i$' co$!i' ratio$. %et6s &e a little more realistic #ith all compo$e$ts. Depe$di$' o$ the load, yo #a$t to see a m ltiple processor system !or yo r data&ase server. 3$e processor is !i$e #ith a lo#8e$d server, i! it is 1,1( or a&ove, & t t#o processors are &etter a$d !o r or more processors are pre!erred. S"% Server is desi'$ed to #or0 &est i$ a symmetric m ltiprocessor e$viro$me$t. ,ive$ the price o! )*M i$ today6s & si$ess e$viro$me$t, it does$6t ma0e a$y se$se to s0imp i$ order to lo#er costs. / t as m ch )*M i$to the machi$e as the hard#are a$d & d'et ca$ ha$dle. +$creasi$' the memory o! a server is the most cost8e!!ective cha$'e yo ca$ ma0e to achieve &etter per!orma$ce o$ a$ e.isti$' machi$e. + hate to eve$ p t a lo# e$d o$ )*M, & t let6s s ''est 1,B !or starters, a$d do$6t &e a!raid to move p a co$sidera&le dista$ce !rom there. The dis0 system is also very importa$t. -or a stro$' server yo sho ld se a mi$im m o! 5 drives. * A8drive )*+D array #o ld &e sed to store data, a$d the other 2 drives #o ld mirror each other a$d store the operati$' system a$d applicatio$ pro'rams. The more drives yo ca$ add i$to the array, the &etter the per!orma$ce a$d the lar'er the capacity availa&le to store data. This pea0s o t at a&o t 10 drives, #hich is a little over&oard a$y#ay, & t a 58drive array per!orms very #ell !or most impleme$tatio$s. )*+D Bred $da$t array o! i$depe$de$t2i$e.pe$sive dis0sC is a tech$olo'y i$ #hich t#o or more dis0 drives ca$ &e co$!i' red i$ s ch a ma$$er as to provide the !ollo#i$':

%ar'er vol mes, &eca se space o$ m ltiple dis0s is com&i$ed to !orm a si$'le vol me +mproved per!orma$ce, &y i$teracti$' #ith more tha$ o$e physical dis0 at a time Bdis0 stripi$'C Sa!e' ardi$' o! data, &y providi$' mecha$isms Bmirror or parityC !or red $da$t data stora'e

Eve$ tho 'h so!t#are impleme$tatio$s o! )*+D m st &e 0$o#$ to pass certi!icatio$ e.ams, a$d #ill &e !o $d i$ prod ctio$ systems, they are $ot $early re'arded as relia&le as hard#are )*+D. -or a$y hi'h8vol me, missio$8critical applicatio$, it is there!ore pre!erred to set p data red $da$cy mecha$isms at the hard#are level.

* 'i'a&it &ac0&o$e sho ld &e co$!i' red !or the $et#or0 aro $d the server. +t is eve$ #orth co$sideri$' m ltiple $et#or0 cards co$$ected to the server to i$crease the &a$d#idth availa&le to the machi$e. +! yo are loo0i$' o$ the very hi'h e$d, the$ t#o sets o! small )*+D arrays o! three drives, each o$ t#o separate co$trollers, ca$ provide some additio$al per!orma$ce 'ai$ a$d !le.i&ility #ith data a$d i$de. placeme$t. +t is also o!te$ recomme$ded that the lo' !iles &e 0ept separated !rom the data so as to improve per!orma$ce a$d red ce dis0 co$te$tio$. TIP Deepi$' the lo' !iles separate !rom the data ca$ help improve per!orma$ce a$d red ce dis0 co$te$tio$.

Defining a SQL Server Database


* data&ase is similar to a #or0 !ile !older, #hich co$tai$s i$!ormatio$ pertai$i$' to related topics. +$ the same #ay, a data&ase is a 'ro p o! !iles sed to store data pertai$i$' to a si$'le & si$ess process. Data&ases are or'a$i(ed #ith !ields, records, a$d ta&les. * !ield is a si$'le characteristic, attri& te, or property that provides i$!ormatio$ a&o t a$ o&4ect. * record is a complete set o! all the !ields com&i$ed to'ether !or a partic lar o&4ect. * ta&le is a 'ro p o! all related records. S"% Server is a relatio$al data&ase ma$a'eme$t system. * relatio$al data&ase co$tai$ed #ithi$ S"% Server is a collectio$ o! o&4ects i$ #hich data a$d other i$!ormatio$ are stored i$ m ltiple ta&les. The $ mero s ta&les are related i$ some #ay, either directly or i$directly via other ta&les. * relatio$al data&ase co$tai$s all data&ase o&4ects, str ct res, a$d ra# data pertai$i$' to that data&ase. Beca se #e have 4 st loo0ed at the hard#are, let6s start #ith a !oc s o$ #here to p t the !iles !or the data&ase server. 3! co$sideratio$ here are the operati$'8system !iles, the applicatio$ pro'ram !iles, a$d the data&ase !iles co$sisti$' o! t#o types o! !iles: data files and log files. +t is also #orth co$sideri$' the separatio$ o! i$de.es &eca se some per!orma$ce 'ai$s ca$ &e reali(ed i! the i$de.es are stored o$ a drive other tha$ the o$e o$ #hich the data is stored. This is do$e thro 'h the se o! !ile'ro ps. 7he$ the i$de. is created o$ a di!!ere$t !ile'ro p, each 'ro p ca$ ma0e se o! di!!ere$t physical drives a$d their o#$ co$trollers. Data a$d i$de. i$!ormatio$ ca$ the$ &e read i$ parallel &y m ltiple dis0 heads. +$ a$ ideal co$!i' ratio$ Bsome#hat to$' e i$ chee0C, yo mi'ht #a$t to separate the operati$' system !rom its pa'e !ile. Eo #o ld the$ place the lo' o$to its o$e drive, separate !rom the data, #ith the data co$!i' red over a )*+D vol me as descri&ed i$ the !ollo#i$' sectio$. Eo 6d the$ ta0e the seldom8 sed data Bcol m$ or ta&le dataC a$d separate it !rom data that #ill &e accessed more !re5 e$tly. *!ter placi$' the i$de.es o!! o$ their o#$ vol me as #ell, !or a&o t F150,000>F200,000 yo #o ld have the optim m per!orma$ce i$ a data&ase server. )emem&er that the DBMS #ill rely heavily o$ the !ile system. The !ile !ormat i$ S"% Server 2000 has $ot si'$i!ica$tly cha$'ed !rom the previo s versio$ BS"% Server ?C. S"% Server ses a set o! !iles to store the data, i$de.es, a$d lo' i$!ormatio$ !or a data&ase. * primary !ile also has some header i$!ormatio$ i$ it, providi$' S"% Server #ith $ecessary i$!ormatio$ a&o t a data&ase. Each data&ase has a mi$im m o! t#o !iles associated #ith it, o$e !or the data a$d a seco$d !or the lo'. +t is also possi&le to create m ltiple !iles !or each o! these p rposes as descri&ed i$ the !ollo#i$' para'raphs. -ile placeme$t, a$d o&4ect placeme$t #ithi$ these !iles, plays a$ importa$t role i$ the respo$sive$ess o! S"% Server. * data&ase co$sists o! t#o or more !iles #ith each !ile sed !or o$ly a si$'le data&ase. * si$'le !ile ca$$ot &e shared &y m ltiple data&ases. The ile System Each data&ase has o$e or more !iles sed to store i$de.es a$d data. +$ a lot o! data&ase sce$arios, yo #ill $ot impleme$t more tha$ o$e data !ile a$d o$e lo' !ile. +$ some i$sta$ces, ho#ever, yo mi'ht #a$t to impleme$t a !ile'ro p. Eo mi'ht also have a per!orma$ce 'ai$ thro 'h the appropriate placeme$t o! o&4ects #ithi$ these 'ro ps. The !irst !ile created !or this p rpose is re!erred to as the primary file. The primary !ile co$tai$s the i$!ormatio$ $eeded to start p a data&ase a$d is also sed to store some or all o! the data. +! desired, seco$dary !iles ca$ &e created to hold some o! the data a$d other o&4ects. Some data&ases mi'ht &e lar'e e$o 'h or comple. e$o 'h i$ their desi'$ to have m ltiple seco$dary !iles sed !or stora'e. Normally, the lo' is mai$tai$ed i$ a si$'le !ile. The lo' !ile is sed to store cha$'es to the data&ase &e!ore these cha$'es are recorded i$ the data !iles themselves. The stora'e o! i$!ormatio$ i$to lo' !iles i$ this ma$$er e$a&les S"% Server to se these !iles as a$ importa$t part o! its recovery process. Every time the S"% Server is started, it ses the lo' !iles !or each o! the data&ases to determi$e #hat $its o! #or0 #ere still &ei$' ha$dled at the time the server #as stopped. The !ile$ames 'ive$ to all data a$d lo' !iles ca$ &e a$y desired $ame, altho 'h it is recomme$ded that yo select a $ame that i$dicates the co$te$t o! the !ile. The !ile e.te$sio$s !or the primary data !ile, seco$dary data !ileBsC, a$d lo' !iles ca$ also &e a$y chose$ set o! characters. +t is recomme$ded !or co$siste$cy a$d sta$dardi(atio$ that the e.te$sio$s &e .md!, .$d!, a$d .ld! !or the primary, seco$dary, a$d lo' !iles, respectively.

!reating iles and ilegroups


-ile'ro ps e$a&le a 'ro p o! !iles to &e ha$dled as a si$'le $it, a$d th s ma0e impleme$tatio$s that re5 ire m ltiple !iles easier to accommodate. 7ith !ile'ro ps, S"% Server provides a$ admi$istrative mecha$ism o! 'ro pi$' !iles #ithi$ a data&ase. Eo mi'ht #a$t

to impleme$t !ile'ro ps to spread data across more tha$ o$e lo'ical dis0 partitio$ or physical dis0 drive. +$ some cases, this provides !or i$creased per!orma$ce as lo$' as the hard#are is s !!icie$t to optimi(e readi$' a$d #riti$' to m ltiple drives co$c rre$tly. Eo ca$ create a !ile'ro p #he$ a data&ase is created, or yo mi'ht add them later #he$ more !iles are $eeded or desired. *!ter a !ile'ro p has &ee$ assi'$ed to a data&ase, yo ca$$ot move its !iles to a di!!ere$t !ile'ro p. There!ore, a !ile ca$$ot &e a mem&er o! more tha$ o$e !ile'ro p. S"% Server provides !or a lot o! !le.i&ility i$ the impleme$tatio$ o! !ile'ro ps. Ta&les, i$de.es, te.t, $te.t, a$d ima'e data ca$ &e associated #ith a speci!ic !ile'ro p, allocati$' all pa'es to o$e speci!ic 'ro p. -ile'ro ps ca$ co$tai$ o$ly data !ilesG lo' !iles ca$$ot &e part o! a !ile'ro p. +! yo place i$de.es i$to their o#$ !ile'ro p, the i$de. a$d data pa'es ca$ &e ha$dled as separate physical read eleme$ts. +! the associated !ile'ro ps are placed o$to separate physical devices, each ca$ &e read #itho t i$ter!eri$' #ith the readi$' o! the other. This is to say that #hile a$ i$de. is read thro 'h i$ a se5 e$tial ma$$er, the data ca$ &e accessed ra$domly #itho t the $eed !or ma$ip lati$' the physical arm o! a hard drive &ac0 a$d !orth !rom the i$de. a$d the data. This ca$ improve per!orma$ce a$d at the same time save o$ hard#are #ear a$d tear. /laci$' a$ e$tire ta&le o$to its o#$ !ile'ro p o!!ers ma$y &e$e!its. +! yo do so, yo ca$ &ac0 p a ta&le #itho t havi$' to per!orm a m ch lar'er &ac0 p operatio$. *rchived or seldom8 sed data ca$ &e separated !rom the data that is more readily $eeded. 3! co rse, the reverse is tr e: * ta&le that $eeds to &e more readily availa&le #ithi$ a data&ase ca$ &e placed i$to its o#$ !ile'ro p to e$a&le 5 ic0er access. +$ ma$y i$sta$ces, pla$$ed de$ormali(atio$ Bthe p rpose! l creatio$ o! red $da$t dataC ca$ &e com&i$ed #ith this !eat re to o&tai$ the &est respo$se. /laci$' te.t, $te.t, a$d ima'e data i$ their o#$ !ile'ro p ca$ improve applicatio$ per!orma$ce. Co$sider a$ applicatio$ desi'$ that allo#s the data !or these col m$ types to &e !etched o$ly po$ ser re5 est. -re5 e$tly, it is $ot $ecessary !or a ser to vie# pict res a$d e.te$sive $otes #ithi$ a sta$dard 5 ery. Not o$ly does this accommodate &etter8per!ormi$' hard#are, & t it also ca$ provide !aster 5 ery respo$ses a$d less &a$d#idth sat ratio$, &eca se data that is $ot re5 ired is $ot se$t across the $et#or0. -ile'ro ps ca$ provide !or a more e!!ective &ac0 p strate'y !or lar'er data&ase e$viro$me$ts. +! a lar'e data&ase is placed across m ltiple !ile'ro ps, the data&ase ca$ &e &ac0ed p i$ smaller pieces. This is a$ importa$t aspect i! the time to per!orm a ! ll &ac0 p o! the e$tire data&ase is too le$'thy. *!ter a determi$atio$ has &ee$ made to se a !ile'ro p strate'y !or stori$' data, al#ays e$s re that #he$ a &ac0 p is per!ormed a'ai$st a !ile'ro p the i$de.es are also &ac0ed p at the same time. This is easily accomplished i! the data a$d i$de.es are stored i$ the same !ile'ro p. +! they are located o$ separate !ile'ro ps, e$s re that &oth the data a$d the i$de. !ile'ro ps are i$cl ded i$ a si$'le &ac0 p operatio$. Be a#are that S"% Server does $ot e$!orce &ac0 p o! data a$d i$de. !ile'ro ps i$ a si$'le operatio$. Eo m st e$s re that the !iles associated #ith the i$de.es tied to a partic lar dataset are &ac0ed p #ith the data d ri$' a !ile'ro p &ac0 p. 3&4ects ca$ easily &e moved !rom o$e !ile'ro p to a$other. Hsi$' the appropriate property pa'e, yo 4 st select the $e# !ile'ro p i$to #hich yo #a$t to move the o&4ect. %o's are $ot stored i$ !ile'ro ps. Eo ca$, ho#ever, se m ltiple lo' !iles a$d place them i$ di!!ere$t locatio$s to o&tai$ &etter a$d more varied mai$te$a$ce a$d allo# more stora'e space !or lo' co$te$t.

ile Placement for Performance and "eliability


The placeme$t o! the !iles related to a S"% Server 2000 data&ase e$viro$me$t helps to e$s re optim m per!orma$ce #hile mi$imi(i$' admi$istratio$. )ecovera&ility ca$ also &e improved i$ the eve$t o! data corr ptio$ or hard#are !ail res i! appropriate meas res are ta0e$. 3$ the e.am, yo m st &e prepared to respo$d to these re5 ireme$ts a$d properly co$!i' re the i$teractio$s #ith the !ile system. +t is a&sol tely ma$datory to $dersta$d the &asics o! the !ile system a$d its se &y S"% Server. D$o# #he$ to split o!! a portio$ o! the data&ase str ct re a$d stora'e to a separate physical dis0 drive. Ma$y processes per!ormed #ithi$ S"% Server ca$ &e classi!ied as se5 e$tial or ra$dom. +$ a se5 e$tial process, the data or !ile ca$ &e read i$ a !or#ard pro'ressio$ #itho t havi$' to locate the $e.t data to &e read. +$ a ra$dom process, the data is typically more spread o t, a$d 'etti$' at the act al physical data re5 ires m ltiple accesses. 7here possi&le, it is desira&le to 0eep se5 e$tial processes r $$i$' #itho t physical i$terr ptio$ ca sed &y other processes co$te$di$' !or the device. Hsi$' !ile placeme$t strate'ies to 0eep ra$dom processes separate !rom se5 e$tial o$es e$a&les the co$!i' ratio$ to mi$imi(e the competitio$ over the placeme$t o! the read2#rite heads. *s a mi$im m re5 ireme$t !or almost a$y impleme$tatio$, yo sho ld separate the $ormal se5 e$tial processi$' o! the lo' !iles !rom the ra$dom processi$' o! the data. Eo also improve recovera&ility &y separati$' the data !rom the lo' a$d placi$' them o$ separate physical vol mes. +! the vol me #here the data is stored is dama'ed a$d m st &e restored !rom &ac0 p, yo #ill still have access to the last lo' e$tries. The !i$al lo' ca$ &e &ac0ed p a$d restored a'ai$st the data&ase, #hich 'ives somethi$' very close to 100I recovera&ility ri'ht to the poi$t o! !ail re. *$ i$teresti$' a$d !le.i&le strate'y is to provide a separate drive solely !or the lo'. This si$'le vol me does $ot have to participate i$ )*+D architect re, & t )*+D mi'ht &e desired !or ! ll recovera&ility. +! yo 'ive the lo' the space o! a$ e$tire vol me, yo 'ive the lo' more room to 'ro# a$d acc m late over time #itho t the $eed !or periodic emptyi$'. %ess !re5 e$t lo' &ac0 ps are $eeded a$d the &est possi&le lo' per!orma$ce is achieved. T#o primary co$cer$s i$ most data e$viro$me$ts are data recovera&ility i$ the eve$t o! the i$evita&le !ail res a$d co$sideratio$s !or mi$imal do#$time. +$ the i$d stry, o$e o! the optim m rati$'s to strive !or is the el sive J!ive $i$esJ B==.===C. This rati$' mea$s that

over a$y 'ive$ period Ba 'e$erally accepted sta$dard o! A:5 days mi$im mC, the server remai$ed o$li$e a$d servici$' the e$d ser ==.===I o! the time. +$ other #ords, the total do#$time !or a$ e$tire year #o ld &e a little more tha$ !ive mi$ tes. Database !reation *$ a&sol te $ecessity o! & ildi$' data&ases that i$teract #ith S"% Server 2000 is si$' the appropriate data&ase o&4ects to o&tai$ a sa&le data&ase system #hile improvi$' respo$se times a$d mai$tai$i$' data i$te'rity. There are co$sideratio$s a$d trade8o!!s !or choosi$' o$e tech$i5 e over the other. The selectio$ o! the most appropriate method to o&tai$ the desired res lt re5 ires that yo 0$o# #here each tech$i5 e is &est impleme$ted. The e.am #ill test o$ the appropriate applicatio$ o! each o! these o&4ects. Creati$' a$d alteri$' data&ases i$volves selecti$' the physical vol me type !or each data&ase !ile, setti$' the appropriate !ile properties, placi$' the o&4ects i$to the !iles2!ile'ro ps, a$d e$s ri$' that appropriate ad4 stme$ts are made as the data&ase mat res. The type o! & si$ess $eeds that the data&ase is &ei$' desi'$ed to meet helps to i$dicate the meas res $eeded to e$s re ade5 ate per!orma$ce. Try to place o$to separate vol mes a$y !iles that mi'ht te$d to compete #ith each other !or read cycles d ri$' a si$'le operatio$. /lace lo' !iles a#ay !rom the data to e$s re ade5 ate recovery, a$d ma0e s re that data&ase properties have &ee$ set i$ s ch a #ay as to e$s re that mai$te$a$ce tas0s ca$ &e per!ormed. 7he$ yo create a data&ase !or the !irst time, that data&ase i$itially ta0es most o! its attri& tes !rom the Model data&ase. The Model data&ase is a system data&ase that S"% Server ses as a 0i$d o! template !or data&ase creatio$s. +t is a 'ood a$d commo$ practice to set the properties a$d co$te$ts o! the Model data&ase &ased o$ the ma4ority o! $e# data&ases that are to &e created. +$ practice, ma$y o&4ects are stored i$ the Model data&ase to mi$imi(e the $eed to re8create these o&4ects every time a data&ase is created. Commo$ eleme$ts placed i$ the Model o!te$ i$cl de speciali(ed ser8de!i$ed ! $ctio$s a$d data types that are prese$t a$d !re5 e$tly sed &y the developme$t sta!! i$ their codi$'. +$ theory, o&4ects are created !or se i$ a si$'le data&ase, & t all developers reali(e that o&4ect a$d code re se is a$ importa$t !acet o! easi$' the developme$t process. 3!te$ a$ o&4ect, s ch as a ser8de!i$ed ! $ctio$, sta$dard sec rity role, or corporate i$!ormatio$ ta&le, ca$ &e !o $d i$ most i! $ot all data&ases #ithi$ a compa$y. * property val e, s ch as recovery level, mi'ht also have a sta$dard impleme$tatio$ across all servers i$ the e$terprise. +! a$ o&4ect or a property val e #ill &e prese$t i$ most o! the ser data&ases, placi$' the o&4ect i$to the Model data&ase or setti$' a property accordi$'ly ca$ save yo the #or0 o! per!ormi$' the activity as a post8creatio$ tas0. *ll !iles $eeded !or a data&ase ca$ &e created thro 'h a si$'le activity si$' S"% Server6s E$terprise Ma$a'er Bas sho#$ i$ -i' re A.1C or #ith a si$'le CREATE DATABASE Tra$sact S"% stateme$t. Either o! these methods ca$ &e sed to i$itiali(e all !iles a$d create the data&ase a$d lo's i$ a si$'le step.

-i' re A.1 Data&ase creatio$ !rom the E$terprise Ma$a'er. S"% Server 2000 e$a&les yo to set data&ase !iles so that they e.pa$d a$d shri$0 a tomatically, elimi$ati$' the $eed !or additio$al admi$istratio$. By de!a lt, S"% Server e$a&les data !iles to i$crease i$ si(e as $eeded !or data stora'e. There!ore, a !ile ca$ 'ro# to the poi$t #here all dis0 space is e.ha sted. Eo ca$ speci!y that a !ile is $ot to 'ro# &eyo$d its creatio$ si(e or impleme$t a ma.im m

si(e !or !ile 'ro#th. E$s re that dis0 space is $ot e.ha sted &y si$' the MAXSIZE optio$ o! the CREATE DATABASE or ALTER DATABASE stateme$ts to i$dicate the lar'est si(e to #hich a !ile ca$ 'ro#. The de!a lt $ames !or the primary data&ase a$d tra$sactio$ lo' !iles are created si$' the data&ase $ame yo speci!ied as the pre!i. 9!or e.ample, NewDatabase_Data.mdf a$d NewDatabase_Log.ldf. These $ames a$d locatio$s ca$ &e cha$'ed, i! desired, !rom the de!a lt val es provided !or the $e# data&ase !ile. The T8S"% sy$ta. !or creati$' a simple data&ase is as !ollo#s:

CREATE DATABASE MyDatabase ON NAME ! "DataSto#e$% &ILENAME ! "d'(data d)#e*to#y(DataSto#e_MyDatabase.mdf$% SIZE ! +MB% MAXSIZE ! ,MB% &ILE-RO.T/ ! +MB0 LO- ON NAME !$LogSto#e$% &ILENAME ! "e'(log d)#e*to#y(LogSto#e_MyDatabase.ldf$% SIZE ! +MB% MAXSIZE ! ,MB% &ILE-RO.T/ ! +MB0
-ollo#i$' are some importa$t iss es #ith re'ard to appropriate se o! the C)E*TE D*T*B*SE stateme$t:

The de!a lt 'ro#th i$creme$t meas re is MB, & t it ca$ also &e speci!ied #ith a DB or a I s !!i.. 7he$ I is speci!ied, the 'ro#th i$creme$t si(e is the speci!ied perce$ta'e o! the si(e o! the !ile at the time the i$creme$t occ rs. * ma.im m o! A2,?:? data&ases ca$ &e de!i$ed o$ a server. The mi$im m si(e !or a lo' !ile is 512DB. Each data&ase has a$ o#$er. The o#$er is the ser #ho creates the data&ase. The data&ase o#$er ca$ &e cha$'ed thro 'h s1_*2a3gedbow3e#. The Master data&ase sho ld &e &ac0ed p a!ter a ser data&ase is created. The de!a lt $it o! meas re !or the s)4e a$d ma5s)4e setti$'s is MB i! yo s pply a $ m&er, & t $o meas re is provided. +! $o optio$s are s pplied, ma5s)4e de!a lts to 63l)m)ted a$d the f)leg#owt2 is +78.

+$ a volatile e$viro$me$t, the data&ase a$d its related !iles mi'ht !re5 e$tly i$crease a$d decrease i$ si(e, a$d this activity mi'ht &e the desired operatio$ o! the server. +$ most i$sta$ces, a$ impleme$tatio$ providi$' !or more sta&ility i$ the !ile system is the desired res lt. * determi$atio$ has to &e made as to #hether the data&ase stays at a&o t the same si(e or 'ro#s or shri$0s over time. +$ most sce$arios, a data&ase 'ro#s over time a$d $eeds to &e red ced o$ly #he$ data is archived. 7he$ creati$' the !iles, yo sho ld set the SIZE, MAXSIZE, a$d &ILE-RO.T/ parameters so that the data&ase ca$ i$crease i$ vol me over time. The &ILE-RO.T/ co$!i' ratio$ sho ld &e impleme$ted i$ lar'er i$creme$ts so that 'ro#th #ithi$ the !ile system is$6t occ pyi$' too m ch o! the server6s reso rces. ,ro#th o! !iles occ rs i$ the &ac0'ro $d a$d ca$ &e mi$imi(ed &y si$' a lar'er 'ro#th i$creme$t. *l#ays provide a MAXSIZE e$try eve$ i! the e$try itsel! is close to the capacity o! the vol me. Eo ca$ se the CREATE DATABASE stateme$t to create a data&ase !rom script. Savi$' the script e$a&les yo to re8create a similar data&ase o$ a$other server i$ the ! t re. *$y S"% Server o&4ect ca$ have its creatio$ script saved. Hsi$' the CREATE DATABASE stateme$t to create a data&ase si$' m ltiple !iles a$d lo' !iles #o ld loo0 similar to this:

CREATE DATABASE E5am1le ON 9RIMAR: NAME ! E5am1leData% &ILENAME ! "*'(mss;l(data(sam1dat.mdf$% SIZE ! +7MB% MAXSIZE ! <7MB% &ILE-RO.T/ ! <MB0% NAME ! E5am1leI3de5es% &ILENAME ! "*'(mss;l(data(sam1)3d<.3df$% SIZE ! +7MB% MAXSIZE ! <7MB% &ILE-RO.T/ ! <MB0% NAME ! E5am1leA#*2)=e% &ILENAME ! "*'(mss;l(data(sam1a#*2.3df$% SIZE ! +7MB% MAXSIZE ! <7MB% &ILE-RO.T/ ! <MB0 LO- ON NAME ! E5am1leLog+% &ILENAME ! "d'(mss;l(log(sam1log+.ldf$%

SIZE ! +7MB% MAXSIZE ! <7MB% &ILE-RO.T/ ! <MB0% NAME ! E5am1leLog<% &ILENAME ! "d'(mss;l(log(sam1log<.ldf$% SIZE ! +7MB% MAXSIZE ! <7MB% &ILE-RO.T/ ! <MB0
7he$ yo create the data&ase a$d its associated !iles, yo provide val es to determi$e the i$itial !ile si(es, i$dicate #hether a$d ho# the !iles #ill 'ro#, a$d speci!y some other &asic data&ase a$d !ile properties. The i$itial setti$'s are sed as a &asis !or ! t re !ile8 system activities. +! the i$itial setti$'s are i$ $eed o! alteratio$ later, yo ca$ per!orm this activity thro 'h the E$terprise Ma$a'er or &y si$' the *%TE) D*TB*SE T8S"% stateme$t. *lteratio$s ca$ impact the !ro$t8e$d applicatio$s, so e.tra ca tio$ m st &e ta0e$ #he$ cha$'i$' a data&ase !rom its ori'i$al !orm. +$ partic lar, the alteratio$ o! the collati$' se5 e$ce ca$ have serio s reperc ssio$s.

#sing a !ollation Se$uence


* collation sequence is a set o! r les 'over$i$' the characters that are sed #ithi$ a data&ase a$d the mea$s &y #hich characters are sorted a$d compared. +$ S"% Server 2000 this se5 e$ce ca$ &e set o$ a data&ase8&y8data&ase &asis. +$ previo s versio$s o! S"% Server, the collatio$ se5 e$ce #as a server8#ide setti$'. Eo there!ore had to either per!orm a #hole series o! re& ildi$' actio$s to create a data&ase that did $ot se the server collatio$, or i$stall the data&ase o$ a separate server alto'ether. +$ S"% Server 2000 yo ca$ speci!y a $o$de!a lt collatio$ !or a$y data&ase o$ the server. This mea$s that o$e data&ase does $ot have to have the same characters or sorti$' r les as the rest o! the data&ases o$ the server. +! all & t o$e or t#o o! yo r data&ases have the same set o! characters, a si$'le server ca$ $o# impleme$t the ! $ctio$ality that previo sly #o ld have ta0e$ t#o separate machi$es. To create a data&ase #ith a $o$de!a lt collati$' se5 e$ce, provide the COLLATE cla se o$ the CREATE DATABASE comma$d. Eo mi'ht also select the collatio$ $ame !rom the drop8do#$ &o. i$ the E$terprise Ma$a'er #he$ yo create the data&ase !rom the ,H+. Collatio$ !or a$ i$divid al col m$ ca$ &e di!!ere$t. * collatio$ ca$ &e selected !or a$ i$divid al col m$ & t is $ot recomme$ded &eca se it ca ses 'reat di!!ic lty i$ the developme$t o! !ro$t8e$d applicatio$s. Be care! l i$ the se o! m ltiple collati$' se5 e$ces &eca se it ma0es the tra$s!er a$d e$try o! data more comple.. +t mi'ht also limit the applicatio$ developme$t e$viro$me$t a$d tech$i5 es $ormally sed !or data e$try a$d editi$'. Be certai$ o! the collatio$ se5 e$ce sed po$ creatio$ o! a data&ase. *!ter the collatio$ se5 e$ce is set, it ca$ &e cha$'ed o$ly thro 'h re& ildi$' o! the data&ase. +! possi&le, collatio$ decisio$s sho ld &e made d ri$' the lo'ical desi'$ o! the system so that yo do$6t have to re& ild. *ltho 'h collatio$s ca$ &e di!!ere$t, i! yo #a$t to cha$'e the se5 e$ce post8creatio$, yo #ill have to re& ild the data&ase.

Altering Database Properties


Several data&ase properties a!!ect the #ay i$ #hich some S"% Server comma$ds operate. Eo ca$ se the E$terprise Ma$a'er to ma0e appropriate ad4 stme$ts to some o! the data&ase properties. *lter$atively, yo ca$ se the ALTER DATABASE T8S"% stateme$t to script these cha$'es. Eo may pre!er setti$' optio$s si$' T8S"%. The system8stored proced re s1_dbo1t)o3 ca$ still &e sed to set data&ase optio$s, & t Microso!t has stated that i$ ! t re versio$s o! S"% Server this ! $ctio$ality mi'ht $ot &e s pported. +$ alteri$' a data&ase, yo ca$ add or remove !iles a$d !ile'ro ps a$d2or modi!y attri& tes o! the !iles a$d !ile'ro ps. ALTER DATABASE also e$a&les yo to set data&ase properties, #hereas i$ previo s versio$s these properties co ld &e cha$'ed o$ly si$' the s1_dbo1t)o3 stored proced re. *!ter yo 6ve set p the optio$s, the $e.t thi$' to co$sider is the creatio$ o! o&4ects #ithi$ the data&ase. Data&ase o&4ects i$cl de co$strai$ts, i$de.es, stored proced res, ta&les, tri''ers, ser8de!i$ed ! $ctio$s, vie#s, a$d more. Each o&4ect is disc ssed i$ detail, payi$' partic lar atte$tio$ to the impact o$ the system as a #hole. +$ ma$y impleme$tatio$s, there are vario s approaches to meeti$' a partic lar $eed. Selecti$' the appropriate tech$i5 e !or a tas0 re5 ires trade8o!!s amo$' ! $ctio$ality, per!orma$ce, a$d reso rce tili(atio$. Inside the Database * data&ase has 5 ite a variety o! o&4ects. Ta&les are ar' a&ly the most importa$t, &eca se they hold the data $ecessary !or the & si$ess system to ! $ctio$, & t they are 4 st the &e'i$$i$' o! the o&4ects yo #ill !i$d prese$t. +$ every data&ase, ser a$d system ali0e, yo #ill !i$d several 'ro ps o! o&4ects, as sho#$ i$ -i' re A.2.

-i' re A.2 S"% Server data&ase o&4ect 'ro pi$'s. Each data&ase is composed o! all o! these o&4ect 'ro pi$'s, tho 'h it is $ot ma$datory !or a data&ase to have some o! the o&4ects. Eve$ i! a partic lar o&4ect is $ot prese$t #ithi$ a data&ase, the 'ro pi$' #ill still &e !o $d. Eo $eed to 0$o# a little a&o t all o! these o&4ects stored i$ the data&ase, tho 'h some are sed more o!te$ tha$ others. D$o#i$' a$ o&4ect6s p rpose co ld save yo !rom selecti$' a$ i$acc rate a$s#er o$ the e.am. +$ partic lar, the ta&le o&4ects, their co$te$t, a$d their relatio$ships m st &e e.pertly 0$o#$.

Tables
Each data&ase co$tai$s a $ m&er o! ta&les other tha$ those sed to store data. These ta&les store i$!ormatio$ that e$a&les S"% Server to 0eep trac0 o! o&4ects a$d proced res #ithi$ the data&ase. The sysob>e*ts a$d sys*omme3ts system ta&les mai$tai$ e$tries co$tai$i$' the o&4ect de!i$itio$s a$d other trac0i$' i$!ormatio$ !or each o&4ect. @ario s other ta&les also e.ist to mai$tai$ i$!ormatio$ a&o t speci!ic o&4ects. -or more i$!ormatio$ re'ardi$' system ta&les, re!er to S"% Server Boo0s 3$li$e. These ta&les are sed #he$ever S"% Server $eeds o&4ect i$!ormatio$. Eo sho ld $ever alter system ta&les directly, & t i$stead allo# S"% Server to ma$ip late the e$tries as $eeded. 7he$ yo 6re de!i$i$' ta&les, it is a 'ood idea to have some !orm o! data dictio$ary prepared to help yo ma0e appropriate choices !or i$divid al properties. * data dictio$ary de!i$es data sa'e a$d is a$ e.te$sio$ o! the lo'ical data modeli$'. +$ S"% Server, the term Jdata&ase dia'ramJ is s ally sed rather tha$ Jdictio$ary,J altho 'h a data&ase dia'ram is $ot a complete data dictio$ary i$ the se$se o! doc me$tatio$.

Diagrams
Dia'rams are o! partic lar i$terest to developers &eca se they ca$ provide a vis al appeara$ce o! the ta&les #ithi$ the data&ase. * data dictio$ary is a !orm o! doc me$tatio$ 'e$erally co$sidered a complete re!ere$ce !or the data it descri&es. The dictio$ary is s ally a lot more tha$ 4 st a collectio$ o! data eleme$t de!i$itio$s. * complete dictio$ary sho ld i$cl de schema #ith re!ere$ce 0eys a$d a$ e$tity8relatio$ship model o! the data eleme$ts or o&4ects. * pse do data dictio$ary ca$ &e represe$ted si$' the data&ase dia'ram tool provided #ith S"% Server, as sho#$ i$ -i' re A.A. There are a lot o! $ice !eat res o! the dia'ram tool that allo# yo to desi'$ a$d e$act cha$'es a'ai$st the data&ase si$' a$ attractive, i$t itive i$ter!ace. +t is a ha$dy tool !or post8impleme$tatio$ doc me$tatio$, as #ell as a trai$i$' assista$t. Doc me$ti$' the ta&les i$ the system is a$ importa$t aspect o! & si$ess applicatio$ developme$t.

-i' re A.A * data&ase dia'ram o! the p &s data&ase.

%iews
* view is a stored 5 ery that is e.ec ted a'ai$st the data stored i$ the ta&les. The ta&les o! the data&ase hold the data i$ ro#s a$d col m$s. @ie#s represe$t the data storedG altho 'h they store $o data, they ca$ still &e sed to represe$t the data i$ col m$s a$d ro#s.

Stored Procedures
*$other e.ec tio$ eleme$t stored #ithi$ the co$te.t o! a data&ase is stored proced res. * stored procedure is a set o! T8S"% stateme$ts that ca$ &e saved as a data&ase o&4ect !or ! t re a$d repeated e.ec tio$s. 7ith stored proced res, yo ca$ e$a&le a lot o! the developme$t a$d processi$' to &e per!ormed o$ the server, prod ci$' m ch more e!!icie$t a$d li'ht#ei'ht !ro$t8e$d applicatio$s. *$y comma$ds that ca$ &e e$tered via S"% " ery tools ca$ &e i$cl ded i$ a stored proced re. Ma$y system8stored proced res have already &ee$ created a$d are availa&le po$ i$stallatio$ o! S"% Server. E.te$ded stored proced res, #hich e$a&le D%% !iles to &e accessed !rom the operati$' system, are preesta&lished a$d prese$t i$ the Master data&ase. E.te$ded stored proced res, li0e ma$y o! the system8stored proced res, are loaded a tomatically #he$ yo i$stall S"% Server. E.te$ded stored proced res access D%% !iles stored o$ the machi$e to e$a&le the calli$' o! the ! $ctio$s co$tai$ed i$ the D%%s !rom #ithi$ a S"% Server applicatio$. Eo mi'ht add to this set o! proced res stored i$ the Master data&ase si$' the s1_adde5te3ded1#o* proced re as sho#$ here:

s1_adde5te3ded1#o* "My&63*t)o3$% "My&63*t)o3Set.DLL$


Stored proced res a$d vie#s ali0e ca$ &e sed as part o! a &roader sec rity pla$.

#sers and "oles


Hsers o! the data&ase either m st &e e.plicitly de!i$ed #ithi$ the ?se#s co$tai$er or m st 'ai$ access &y &elo$'i$' to a 'ro p that ca$ 'ai$ access to the data&ase. )ole8&ased sec rity ca$ also &e impleme$ted at the server, data&ase, or applicatio$ level. *ll o! these aspects ma0e se o! o&4ects stored i$ the data&ase to help sec re the system. Sec ri$' the data&ase is disc ssed later i$ the &oo0 i$ Chapter =, JDesi'$i$' a Data&ase Sec rity /la$.J

"ules
) les are a &ac0#ard8compati&ility !eat re that per!orms some o! the same ! $ctio$s as C/EC@ co$strai$ts. ) les are disc ssed &rie!ly here to e$s re thoro 'h covera'e o! ta&le o&4ects. ) les, ho#ever, are $ot li0ely to &e !o $d o$ the e.am e.cept as a$ i$correct a$s#er. C/EC@ co$strai$ts, #hich are disc ssed later i$ the chapter, are the pre!erred, sta$dard #ay to restrict the val es i$ a col m$. C/EC@ co$strai$ts are also more co$cise tha$ r lesG there ca$ &e o$ly o$e r le applied to a col m$, & t m ltiple C/EC@ co$strai$ts ca$ &e applied. ) les are similar & t are created as separate o&4ects a$d the$ &o $d to the col m$.

Defaults
* DE&A?LT is a$ o&4ect that ca$ &e de!i$ed !or a data&ase a$d is sed &y col m$s o! ta&les #ithi$ the data&ase. * DE&A?LT is sed to provide a val e #he$ $o e.plicit val e is 'ive$ po$ i$p t o! data. * DE&A?LT o&4ect m st &e &o $d to each col m$ to #hich it #ill apply. +! a DE&A?LT o&4ect is &o $d to a col m$, it is still possi&le to speci!y a di!!ere$t de!a lt val e !or that col m$ i$ a a$y 'ive$ ta&le. This impleme$ts a de!a lt co$strai$t a$d $&i$ds the e.isti$' DE&A?LT o&4ect !rom the col m$ &e!ore the $e# de!a lt val e is set. +$ this respect the de!a lt &ecomes a property o! the col m$ as opposed to a separate o&4ect.

#ser&Defined Data Types and unctions


Hser8de!i$ed data types, as e.plai$ed i$ Chapter 1, JData&ase Developme$t o$ S"% Server 2000,J are really 4 st a$ e.te$sio$ o! the S"% Server system data types. Hser8de!i$ed ! $ctio$s are de!i$ed &y the developer to &e sed as a codi$' o&4ect to per!orm a tas0 #ithi$ the & si$ess system. Hser8de!i$ed ! $ctio$s are dealt #ith at le$'th i$ Chapter :, J/ro'rammi$' B si$ess %o'ic.J

ull&Te't !atalogs
The remai$i$' o&4ect 'ro p is sed to hold - ll8Te.t catalo's. These catalo's co$tai$ - ll8Te.t i$de.es that store i$!ormatio$ a&o t si'$i!ica$t #ords a$d their locatio$ #ithi$ a 'ive$ col m$ o! data #ithi$ the data&ase. - ll8Te.t i$de.i$', catalo's, a$d 5 eries to'ether allo# yo to search !or E$'lish #ords #ithi$ te.t !ields. There are also ! ((y search capa&ilities that allo# !or searchi$' si$' #ord !orms a$d similar8so $di$' #ords. CAUTION +$ the past, - ll8Te.t i$de.i$' has &ee$ a co$sidera&le e.am topic, & t it seems to have !alle$ o t o! !avor #ith Microso!t a$d #ill $ot li0ely &e see$ o$ the e.am. *s yo ca$ see, the ma0e p o! a data&ase i$cl des a lot o! di!!ere$t o&4ects, m ch more tha$ 4 st ta&les ! ll o! data. The ma0e p o! a ta&le i$ S"% Server is more tha$ 4 st simply data de!i$itio$. * complete ta&le de!i$itio$ i$cl des col m$ descriptio$s, stora'e locatio$, co$strai$ts, relatio$ships #ith other ta&les, i$de.es, a$d 0eys, as #ell as ta&le8level permissio$s a$d te.t i$de.i$' col m$s.

(hat)s on the Table


*!ter the !ile str ct re a$d co$te$t o! each !ile has &ee$ determi$ed, the ta&les themselves ca$ &e created a$d assi'$ed to the !iles. +! the p rpose o! the ta&le is to hold data that is !re5 e$tly accessed, the !ile placeme$t o! the ta&le sho ld ta0e that i$to co$sideratio$. Ta&les that hold archive data a$d other less !re5 e$tly accessed data re5 ire less mai$te$a$ce a$d do$6t have to &e as respo$sive to ser 5 eries. Deep i$ mi$d #he$ assi'$i$' o&4ects to !iles that some o&4ects ca$ &e placed a#ay !rom the mai$stream data thro 'h the se o! !ile'ro ps. Eo ca$ select the o&4ect placeme$t !rom Ta&le Desi'$ /roperties i$ the E$terprise Ma$a'er or thro 'h the se o! a$ ON cla se i$ a CREATEAALTER stateme$t. S"% Server e$a&les yo to place the !ollo#i$' ta&le o&4ects:

Ta&les +$de.es Te.t, $te.t, or ima'e data

Eo #o$6t $ecessarily al#ays &e movi$' o&4ects aro $d. +$ most i$sta$ces, the applicatio$ #o$6t &e lar'e e$o 'h to 4 sti!y these meas res. Eo $eed to address this sit atio$ o$ly i$ very lar'e data&ase systems.

Data *lement Definition


The i$itial de!i$itio$ o! each col m$ #ithi$ a ta&le co$sists o! a $ame !or the col m$, the type a$d le$'th o! data !or the col m$, a$d a$ i$dicator as to #hether the col m$ m st have data or allo# N?LL co$te$t. * $ m&er o! additio$al col m$ descriptors ca$ &e i$cl ded to de!i$e characteristics o! ho# the col m$ o&tai$s its val e a$d ho# the col m$ is treated #ithi$ the ta&le. * complete list o! pote$tial col m$ descriptors is 'ive$ here:

Col6m3 Name9Sho ld &e mea$i$'! l so as to descri&e the col m$ co$te$t. Data Ty1e9*$y o$e o! 25 possi&le de!i$itio$s provides the &asis !or the data a col m$ #ill co$tai$. Choices i$cl de
several possi&ilities !or each data type. BData types are disc ssed more ! lly later i$ this &oo0.C

Le3gt29-or ma$y o! the data types, the le$'th is predetermi$ed. Eo m st, ho#ever, speci!y a le$'th !or character, H$icode B3C/ARC, a$d &i$ary data. * le$'th m st also &e speci!ied !or varia&le8le$'th data col m$s. +! a *2a# or a$ 3C/AR
data type is o$ly a si$'le character, $o le$'th has to &e de!i$ed.

Allow N6lls9Eo ca$ provide a$ i$dicator !or allo#i$' N?LL co$te$t !or a$y varia&le e.cept those assi'$ed as primary
0eys.

9#)ma#y @ey9E$!orces $i5 e co$te$t !or a col m$ a$d ca$ &e sed to relate other ta&les. M st co$tai$ a $i5 e $o$8 N?LL val e. Des*#)1t)o39/rovides a$ e.pla$atio$ o! the col m$ !or doc me$tatio$ p rposes. BThis is a$ e.te$ded ta&le property.C Defa6lt Bal6e9/rovides a val e !or a col m$ #he$ o$e is $ot e.plicitly 'ive$ d ri$' data e$try. * de!a lt o&4ect m st
&e created a$d the$ &o $d to a col m$, & t the pre!erred tech$i5 e is to provide the de!a lt de!i$itio$, directly attached to the col m$ i$ the CREATEAALTER ta&le de!i$itio$. +t is de!i$ed at the data&ase level a$d ca$ &e tili(ed &y a$y $ m&er o! col m$s i$ a data&ase.

9#e*)s)o39The $ m&er o! di'its i$ a $ meric col m$. S*ale9The $ m&er o! di'its to the ri'ht o! a decimal poi$t i$ a $ meric col m$. Ide3t)ty9+$serts a val e a tomatically i$to a col m$, &ased o$ seed a$d i$creme$t de!i$itio$s. Ide3t)ty Seed9/rovides the starti$' val e !or a$ Ide3t)ty col m$. Ide3t)ty I3*#eme3t9De!i$es ho# a$ Ide3t)ty #ill i$crease or decrease #ith each $e# ro# added to a ta&le. Is Row-6)d9+de$ti!ies a col m$ that has &ee$ de!i$ed #ith the ?3);6e Ide3t)f)e# data type as &ei$' the col m$ to &e sed i$ co$4 $ctio$ #ith the RO.-?IDCOL ! $ctio$ i$ a SELECT list. &o#m6la9/rovides a mea$s o! o&tai$i$' the col m$ co$te$t thro 'h the se o! a ! $ctio$ or calc latio$. Collat)o39Ca$ provide !or a di!!ere$t character set or sort order tha$ other data. BHse #ith e.treme ca tio$, i! at all,
&eca se deali$' #ith di!!ere$t character sets impairs !ro$t8e$d developme$t a$d hampers data i$p t a$d alteratio$ processes.C

Ma$y characteristics o! col m$ de!i$itio$s #ill have a$ impact o$ the de!i$itio$ o! other col m$s, ta&les, a$d data&ases. -or a more complete de!i$itio$ o! a$y o! these properties, co$s lt S"% Server Boo0s 3$li$e.

+eys to Success
* ta&le 0ey is a$ attri& te sed to ide$ti!y a partic lar ro# o! the ta&le. Both primary a$d !orei'$ 0eys are de!i$ed i$ the !orm o! a co$strai$t. These 0eys #or0 to'ether to accommodate ta&le relatio$ships. * !orei'$ 0ey re!ers to the primary 0ey i$ the pare$t ta&le, !ormi$' a o$e8to8o$e or o$e8to8ma$y relatio$ship. )emem&er !rom the disc ssio$ o! the lo'ical desi'$ that a ma$y8to8ma$y relatio$ship is really t#o o$e8to8ma$y relatio$ships si$' a 4oi$i$' ta&le. 7he$ m ltiple ta&les mai$tai$ed i$ a data&ase are related to each other, some meas res sho ld &e ta0e$ to e$s re that the relia&ility o! these relatio$ships stays i$tact. To e$!orce re!ere$tial i$te'rity, yo create a relatio$ship &et#ee$ t#o ta&les. This ca$ &e do$e thro 'h the data&ase dia'ram !eat re o! the E$terprise Ma$a'er or thro 'h the CREATE a$d ALTER TABLE T8S"% stateme$ts. Normally, yo relate the re!ere$ci$' or !orei'$ 0ey o! o$e ta&le to the primary 0ey or other $i5 e val e o! a seco$d ta&le.

PRIMARY !Y Constraint
* 9RIMAR: @E: co$strai$t e$!orces e$tity i$te'rity i$ that it does $ot permit a$y t#o ro#s i$ a ta&le to have the same 0ey val e. This e$a&les each ro# to &e $i5 ely de!i$ed i$ its o#$ ri'ht. *ltho 'h a primary 0ey sho ld &e created #he$ a ta&le is i$itially created, it ca$ &e added or cha$'ed at a$y time a!ter creatio$. The primary 0ey ca$ &e added po$ creatio$ o! the ta&le as 'ive$ here:

CREATE TABLE Ot2e#A6t2o#s a6_)d )d NOT N?LL

CONSTRAINT C?9@CL_ot2a6)3dD 9RIMAR: @E: CL?STERED% a6_l3ame =a#*2a# E70 NOT N?LL % a6_f3ame =a#*2a# <70 NOT N?LL % 12o3e *2a# +<0 NOT N?LL % add#ess =a#*2a# E70 N?LL % *)ty =a#*2a# <70 N?LL % state *2a# <0 N?LL % 4)1 *2a# ,0 N?LL % *o3t#a*t b)t NOT N?LL 0 ON C9RIMAR:D
* primary 0ey ca$$ot have NH%% co$te$t, $or ca$ there &e a$y d plicate val es. S"% Server a tomatically creates a $i5 e i$de. to e$!orce the e.cl sive$ess o! each val e. +! a primary 0ey is re!ere$ced &y a !orei'$ 0ey i$ a$other ta&le, the primary 0ey ca$$ot &e removed $less the !orei'$ 0ey relatio$ship is removed !irst. The de!i$itio$ o! a primary 0ey !or each ta&le, tho 'h $ot a re5 ireme$t o! the S"% Server data&ase e$viro$me$t, is recomme$ded. * primary 0ey helps records mai$tai$ their ide$tities as $i5 e ro#s o! a ta&le a$d also provides a mea$s o! relati$' ta&les to other ta&les i$ the data&ase to mai$tai$ $ormal !orms. B-or ! rther i$!ormatio$ o$ $ormali(atio$ a$d $ormal !orms, see Chapter 2, JCreati$' a %o'ical Data Model.JC * !orei'$ 0ey is de!i$ed i$ a s &sidiary ta&le as a poi$ter to the primary 0ey or other $i5 e val e i$ the primary ta&le to create a relatio$ship. The most commo$ relatio$ships are o$e8to8ma$y, i$ #hich the $i5 e val e i$ o$e ta&le has ma$y s &sidiary records i$ the seco$d ta&le. *$other !orm o! relatio$ship, #hich is $ormally sed to split a ta&le #ith a$ e.traordi$ary $ m&er o! col m$s, is a o$e8to8o$e relatio$ship. The se o! o$e8to8o$e splits a ta&le a$d associates a si$'le $i5 e val e i$ o$e ta&le #ith the same $i5 e val e i$ a seco$d ta&le. * ma$y8to8ma$y relatio$ship ca$ also &e de!i$ed, & t this !orm o! re!ere$ci$' re5 ires three ta&les a$d is really t#o separate o$e8to8ma$y relatio$ships. CAUTION +!, o$ the e.am, yo r $ i$to the topic o! setti$' relatio$ships &ased o$ $i5 e val es, the correct a$s#er is li0ely to &e o$e chose$ &ased o$ the doc me$tatio$ a$d $ot o$ act al ! $ctio$ality. The capa&ility to set a relatio$ship to a$y $i5 e col m$ is $ot $oted i$ doc me$tatio$. The correct tech$i5 e to se #he$ a$s#eri$' a$ e.am 5 estio$ #o ld &e o$e that i$volves a !orei'$ 0ey set to a PRIMARY !Y or UNI"U! co$strai$t. Htili(i$' re!ere$tial i$te'rity ' ideli$es helps mai$tai$ the acc racy o! data e$tered i$to the system. * data&ase system ses re!ere$tial i$te'rity r les to prohi&it s &sidiary eleme$ts !rom &ei$' e$tered i$to the system $less a matchi$' $i5 e eleme$t is i$ the re!ere$ced ta&le. The system also protects the data !rom cha$'es a$d deletio$s, ass mi$' that cascadi$' actio$s Bde!i$ed later i$ this chapterC have &ee$ care! lly a$d properly impleme$ted.

#OR!I$N

!Y Constraint

* &OREI-N @E: co$strai$t is de!i$ed so that a primary a$d s &sidiary ta&le ca$ &e li$0ed to'ether &y a commo$ val e. * !orei'$ 0ey ca$ &e li$0ed to a$y $i5 e col m$ i$ the mai$ ta&leG it does $ot $ecessarily have to &e li$0ed to the primary 0ey. +t ca$ &e li$0ed to a$y col m$ that is associated #ith a $i5 e i$de.. Eo ca$ de!i$e a !orei'$ 0ey a$d its relatio$ship #he$ creati$' or alteri$' a ta&le de!i$itio$. The !ollo#i$' e.ample de!i$es a relatio$ship si$' T8S"%:

CREATE TABLE O#de#Deta)ls Deta)lsID small)3t% O#de#ID small)3t &OREI-N @E: O#de#ID0 RE&ERENCES O#de#s O#de#ID0% FtyO#de#ed b)g)3t% .a#e2o6seLo*at)o3 small)3t 0
7ith a !orei'$ 0ey de!i$ed, yo ca$$ot add a val e to the !orei'$ 0ey col m$ i! a matchi$' val e is $ot prese$t i$ the primary ta&le. +! a child e$try #ith a$ +D is $ot !o $d i$ the pare$t ta&le, the$ that is 0$o#$ as a$ orpha$ child a$d is a &reach o! re!ere$tial i$te'rity r les.

#sing !ascade Action


Ne# to S"% Server #ith the 2000 release is a cascadi$' actio$ !eat re that ma$y other data&ase e$viro$me$ts have &ee$ e$4oyi$' !or 5 ite some time. Cascadi$' actio$s a!!ect pdate a$d delete activity #he$ a$ e.isti$' !orei'$ 0ey val e is cha$'ed or removed. Cascade actio$ is co$trolled thro 'h the CREATE a$d ALTER TABLE stateme$ts, #ith cla ses !or ON DELETE a$d ON ?9DATE. Eo ca$ also select these !eat res si$' the E$terprise Ma$a'er. CAUTION

The cascadi$' actio$s !eat re is a $e# !eat re, a$d yo ca$ e.pect that somethi$' a&o t it #ill &e as0ed o$ the e.am. *lso &e prepared !or the e.am &y 0$o#i$' all the res lts a$d implicatio$s o! cascadi$' actio$s. -or e.ample, yo mi'ht &e as0ed #hat occ rs #he$ a record co$tai$ed i$ the pare$t ta&le is deleted or has its 0ey val e cha$'ed. +$ a cascadi$' pdate, #he$ yo cha$'e the val e o! a 0ey i$ a sit atio$ i$ #hich a !orei'$ 0ey i$ a$other ta&le re!ere$ces the 0ey val e, those cha$'ed val es are re!lected &ac0 to the other ta&les. * similar thi$' happe$s #ith a delete operatio$: +! a record is deleted, all s &sidiary records i$ other ta&les are also deleted. -or e.ample, i! a$ i$voice record is deleted !rom a$ i$voice ta&le that has i$voice details stored i$ a$other ta&le a$d re!ere$ced &y a !orei'$ 0ey, the$ the details #o ld also &e removed. * series o! cascadi$' actio$s co ld easily res lt !rom the pdate or deletio$ o! importa$t 0eys. -or e.ample, the deletio$ o! a c stomer co ld ca se the deletio$ o! all that c stomer6s orders, #hich co ld ca se the deletio$ o! all the c stomer6s i$voices, #hich i$ t r$ co ld ca se the deletio$ o! all the c stomer6s i$voice details. -or this reaso$, care! l system desi'$ is importa$t, a$d the pote$tial archivi$' o! data thro 'h the se o! tri''ers sho ld &e co$sidered. +$ the case o! m ltiple cascadi$' actio$s, all the tri''ers to &e !ired &y the e!!ects o! the ori'i$al deletio$ !ire !irst. A&TER tri''ers the$ !ire o$ the ori'i$al ta&le, a$d the$ the A&TER tri''ers i$ the ta&le chai$ s &se5 e$tly !ire.

,aintaining -rder with Inde'es


/ tti$' the data i$to se5 e$ce to accommodate 5 ic0 retrieval, a$d at the same time provide mea$i$'! l a$d sa&le o tp t to a$ applicatio$, s ally re5 ires that a variety o! i$de.es &e de!i$ed. * cl stered i$de. provides the physical order o! the data &ei$' stored, #hereas a $o$cl stered i$de. provides a$ ordered list #ith poi$ters to the physical locatio$ o! the data. +$de.i$' is most easily de!i$ed a$d $derstood i! yo compare the data a$d i$de. stora'e o! a data&ase to that o! a &oo0. +$ a &oo0 the data itsel! is placed o$to the pa'es i$ a se5 e$ce that is mea$i$'! l i! yo read the &oo0 se5 e$tially !rom cover to cover. *$ i$de. at the &ac0 o! the &oo0 e$a&les yo to read the data ra$domly. Eo ca$ locate a topic &y loo0i$' thro 'h a list o! topics that is accompa$ied &y a physical pa'e re!ere$ce to the place #here the topic ca$ &e !o $d. To read a si$'le topic, yo $eed $ot s0im thro 'h the e$tire &oo0. +$ a similar ma$$er, data i$ a data&ase ca$ &e ha$dled ra$domly or i$ se5 e$ce. * si$'le record ca$ &e located i$ the data&ase &y loo0i$' it p i$ the i$de., rather tha$ readi$' thro 'h all the rest o! the data. Co$versely, i! a report is to &e 'e$erated !rom all the data i$ a data&ase, the data itsel! ca$ &e read se5 e$tially i$ its e$tirety. +$de. stora'e i$ S"% Server has a B8tree str ct red stora'e. The i$de.es are mai$tai$ed i$ <DB pa'es 5 ali!ied as root, i$termediate, a$d lea!8level pa'es. +$ a cl stered i$de. the lea! level is the data itsel!, a$d all other levels represe$t i$de. pa'es. +$ a $o$cl stered i$de. all pa'es co$tai$ i$de.es Bsee -i' re A.;C.

-i' re A.; B8tree str ct re sed !or cl stered i$de.es. +! a cl stered i$de. has $ot &ee$ de!i$ed !or a 'ive$ ta&le, the data is stored i$ a Jheap.J * data heap does $ot mai$tai$ data i$ a$y partic lar orderG it simply stores the data i$ the order i$ #hich it is e$tered. +$ some applicatio$s, i$ #hich data is $ever retrieved i$ a$y partic lar order o$ a re' lar &asis, this mi'ht act ally &e adva$ta'eo s. +$de.es ca$ &e created si$' the T8S"% CREATE INDEX comma$d. 7he$ yo 6re creati$' i$de.es, it is 'ood practice to leave space !or later i$sertio$s o! data. The !ollo#i$' e.ample creates a compo $d, $o$cl stered i$de. that is ?5I ! ll:

CREATE INDEX IX9#od6*tItem ON 9#od6*tO#de#L)3e O#de#Mate@ey% 9#od6*tL)3e@ey0 .IT/ &ILL&ACTOR ! G,


The t#o di!!ere$t or'a$i(atio$s o! i$de.es, clustered a$d nonclustered, provide !or the orderi$' o! data either thro 'h physically rearra$'i$' the data as i$ a cl stered i$de. or thro 'h the se o! data poi$ters as i$ a $o$cl stered i$de.. +! the or'a$i(atio$ is $ot speci!ied, as i$ the previo s e.ample, $o$cl stered #ill &e de!a lted to.

Inde%in& Throu&h Reorderin&'Clustered


The selectio$ o! the appropriate col m$BsC o$ #hich to &ase a cl stered i$de. is importa$t !or several reaso$s. *s previo sly me$tio$ed, a cl stered i$de. represe$ts the order i$ #hich the data is physically stored o$ the dis0. -or this reaso$, yo ca$ de!i$e o$ly a si$'le cl stered i$de. !or a$y ta&le. +! yo choose $ot to se a cl stered i$de. i$ a ta&le, the data o$ the dis0 #ill &e stored i$ a heap. * cl stered i$de., i! prese$t, has cl steri$' 0eys that are sed &y all $o$cl stered i$de.es to determi$e the physical locatio$ o! the data. The &asis !or the i$de. s ally is determi$ed &y the order i$ #hich the ma4ority o! applicatio$s a$d 5 eries #a$t their o tp t. The cl stered i$de. val es are also prese$t i$ other i$de.es, a$d the si(e o! the de!i$ed i$de. sho ld &e 0ept as small as possi&le. 7he$ yo select a cl steri$' 0ey, try to tili(e a $ meric data type &eca se character types ca se i$de. stora'e to occ py m ch more space. *l#ays de!i$e a cl stered i$de. !irst &e!ore yo de!i$e a$y o! the $o$cl stered i$de.es. +! yo do these tas0s i$ reverse order, all $o$cl stered i$de.es re& ild themselves po$ creatio$ o! the cl stered i$de..

Inde%in& Throu&h (ata Pointers'Nonclustered


No$cl stered i$de.es provide a mea$s o! retrievi$' the data !rom the data&ase i$ a$ order other tha$ that i$ #hich the data is physically stored. The o$ly alter$ative to the se o! these i$de.es #o ld &e provisio$s !or a sort operatio$ that #o ld place $d e overhead o$ the clie$t system a$d mi'ht $ot prod ce the desired respo$se times. * data sort impleme$tatio$ is s ally per!ormed o$ly !or o$e8time operatio$s or !or applicatio$s that #ill have very limited sa'e. *ltho 'h the creatio$ o! i$de.es saves time a$d reso rces i$ a lot o! cases, avoid the creatio$ o! i$de.es that #ill rarely &e tili(ed. Each time a record is added to a ta&le, all i$de.es i$ the ta&le m st &e pdated, a$d this mi'ht also ca se $d e system overhead. -or that reaso$, care! l pla$$i$' o! i$de. sa'e is $ecessary.

One o) a

ind'Unique Inde%in&

7he$ i$de.es are created, it is importa$t to ' ara$tee that each val e is disti$ctive. This is partic larly importa$t !or a primary 0ey. S"% Server a tomatically applies a $i5 e i$de. to a primary 0ey to e$s re that each 0ey val e $i5 ely de!i$es a ro# i$ the ta&le. Eo mi'ht #a$t to create additio$al $i5 e i$de.es !or col m$s that are $ot 'oi$' to &e de!i$ed as the primary 0ey.

"oom for Additions


-ill !actor is the perce$t at #hich S"% Server !ills lea!8level pa'es po$ creatio$ o! i$de.es. /rovisio$ !or empty pa'es e$a&les the server to i$sert additio$al ro#s #itho t per!ormi$' a pa'e8split operatio$. * pa'e split occ rs #he$ a $e# ro# is i$serted i$to a ta&le that has $o empty space !or its placeme$t. *s the stora'e pa'es !ill, pa'e splits occ r, #hich ca$ hamper per!orma$ce a$d i$crease !ra'me$tatio$. Eo #ill $ormally !i$d that 5 eries Bthe readi$' o! e.isti$' dataC o t#ei'h data pdates &y a s &sta$tial mar'i$. /rovidi$' the e.tra room slo#s do#$ the 5 ery process. There!ore, yo mi'ht $ot #a$t to ad4 st the !ill !actor val e at all i$ static systems i$ #hich there are smaller $ m&ers o! additio$s. E5 ally, setti$' the !ill !actor too lo# hampers read per!orma$ce &eca se the server m st $e'otiate a series o! empty pa'es to act ally !etch the desired data. +t is &e$e!icial to speci!y a !ill !actor #he$ yo create a$ i$de. o$ a ta&le that already has data a$d #ill have a hi'h vol me o! i$serts. +! yo do $ot speci!y this setti$' #he$ creati$' a$ i$de., the server de!a lt !ill !actor setti$' is chose$. The !ill !actor !or the server is a co$!i' ratio$ optio$ set thro 'h the E$terprise Ma$a'er or the s1_*o3f)g6#e stored proced re. The perce$ta'e val e !or the !ill !actor is $ot mai$tai$ed over timeG it applies o$ly at the time o! creatio$. There!ore, i! i$serts i$to a ta&le occ r !re5 e$tly, it6s importa$t to ta0e mai$te$a$ce meas res !or re& ildi$' the i$de.es to e$s re that the empty space is p t &ac0 i$ place. * speci!ic i$de. ca$ &e re& ilt si$' the CREATE INDEX T8S"% comma$d #ith the DRO9 EXISTIN- optio$. +$de.es ca$ also &e de!ra'me$ted si$' the DBCC INDEXDE&RA- comma$d, #hich also reapplies the !ill !actor. The /ad +$de. setti$' is closely related to the setti$' !or !ill !actor to allo# space to &e le!t i$ $o$8lea! levels. /ad +$de. ca$$ot &e speci!ied &y itsel! a$d ca$ &e sed o$ly i! yo s pply a !ill !actor. Eo do $ot provide a val e !or this setti$'G it matches the setti$' 'ive$ !or the !ill !actor.

Data *ntry #sing Defaults

* de!a lt is sed to provide a val e !or a col m$ to mi$imi(e data e$try e!!orts or to provide a$ e$try #he$ the data is $ot 0$o#$. * de!a lt provides a val e !or the col m$ as a &asis !or i$itial i$p t. *$y data that is e$tered !or the col m$ overrides the de!a lt e$try. Eo ca$ apply a de!a lt de!i$itio$ to a col m$ directly si$' the CREATE or ALTER TABLE stateme$t or thro 'h the Desi'$ Ta&le optio$ !rom #ithi$ the E$terprise Ma$a'er. Eo ca$ also create a de!a lt as its o#$ o&4ect a$d the$ &i$d it to o$e or more col m$s. * de!a lt de!i$itio$ that is provided as part o! a ta&le de!i$itio$ is a sta$dard a$d pre!erred method o! impleme$ti$' de!a lt e$tries. The adva$ta'es o! this tech$i5 e are that the de!a lt is dropped #he$ the ta&le is dropped a$d that the de!i$itio$ is stored #ithi$ the ta&le itsel!. * de!a lt o&4ect m st &e created a$d &o $d to the col m$ i$ a t#o8step operatio$. To create a$d &i$d a de!a lt o&4ect, se the !ollo#i$' code:

CREATE DE&A?LT StateDefa6lt AS "IN$ s1_b)3defa6lt StateDefa6lt% "*6stome#s.state$ To *#eate a defa6lt w)t2)3 a table def)3)t)o3% 6se t2e follow)3g' CREATE TABLE Sam1leDefa6lt Sam1leID small)3t NOT N?LL CONSTRAINT ?9@CL_Sam1leID 9RIMAR: @E: CL?STERED% C)ty =a#*2a# ,70 DE&A?LT ".oodsto*H$0% State *2a# <0 DE&A?LT "N:$0 0
7he$ a$ +NSE)T operatio$ is per!ormed o$ a ta&le, yo m st s pply val es !or all col m$s that do $ot have a de!a lt e$try de!i$ed or that do $ot allo# NH%% co$te$t.

!hec.s and /alances


* C/EC@ co$strai$t is o$e o! several mecha$isms that ca$ &e sed to preve$t i$correct data !rom e$teri$' the system. )estrictio$s o$ data e$try ca$ &e applied at the ta&le or col m$ level thro 'h the se o! a C/EC@ co$strai$t. Eo mi'ht also apply more tha$ a si$'le chec0 to a$y o$e col m$, i$ #hich case the chec0s are eval ated i$ the order i$ #hich they #ere created. * C/EC@ co$strai$t represe$ts a$y Boolea$ e.pressio$ that is applied to the data to determi$e #hether the data meets the criteria o! the chec0. The adva$ta'e o! si$' a chec0 is that it is applied to the data &e!ore it e$ters the system. 1o#ever, C/EC@ co$strai$ts do have less ! $ctio$ality tha$ mecha$isms, s ch as stored proced res or tri''ers. 3$e se !or a C/EC@ co$strai$t is to e$s re that a val e e$tered meets 'ive$ criteria &ased o$ a$other val e e$tered. * ta&le8level C/EC@ co$strai$t is de!i$ed at the &ottom o! the ALTERACREATE TABLE stateme$t, $li0e a COL?MN C/EC@ co$strai$t, #hich is de!i$ed as part o! the col m$ de!i$itio$. -or e.ample, #he$ a d e date e$tered m st &e at least A0 days &eyo$d a$ i$voice date, a ta&le8level co$strai$t #o ld &e de!i$ed this #ay:

D6eDate I I3=o)*eDate0 J! K7
* col m$8level chec0 mi'ht &e sed to e$s re that data is #ithi$ accepta&le ra$'es, s ch as i$ the !ollo#i$':

I3=o)*eAmo63t J! + AND I3=o)*eAmo63t L! <,777


* chec0 ca$ also de!i$e the patter$ or !ormat i$ #hich data val es are e$tered. Eo mi'ht, !or e.ample, #a$t a$ i$voice $ m&er to have a$ alpha&etic character i$ the !irst positio$, !ollo#ed &y !ive $ meric val es, i$ #hich case the chec0 mi'ht loo0 similar to the !ollo#i$':

I3=o)*eN6mbe# LI@E "CAIZDC7IMDC7IMDC7IMDC7IMDC7IMD$


-i$ally, yo mi'ht #a$t to apply a chec0 #he$ a$ e$try m st &e !rom a ra$'e o! $ m&er choices #ithi$ a list. *$ i$ve$tory item that m st &e o$e o! a series o! cate'ory choices mi'ht loo0 similar to this:

9#od6*tCatego#y IN

"/ARD.ARE$% "SO&T.ARE$% "SERBICE$0

* C3%HMN C1ECD Bor other co$strai$tC is stated as a portio$ o! the col m$ de!i$itio$ itsel! a$d applies o$ly to the col m$ #here it is de!i$ed. * T*B%E C1ECD Bor other co$strai$tC, o$ the other ha$d, is de!i$ed i$depe$de$tly o! a$y col m$, ca$ &e applied to more tha$ o$e col m$, a$d m st &e sed i! more tha$ o$e col m$ is i$cl ded i$ the co$strai$t. * ta&le de!i$itio$ that is to de!i$e restrictio$s to a si$'le col m$ Bmi$im m 5 a$tity ordered is 50C, as #ell as a ta&le co$strai$t Bdate o$ #hich part is re5 ired m st &e later tha$ #he$ orderedC, #o ld &e as sho#$ here:

CREATE TABLE 9#od6*tO#de#L)3e 9#od6*tL)3e@ey B)gI3t%

O#de#Mat*2@ey B)gI3t% 9#od6*tO#de#ed C2a# N0% FtyO#de#ed B)gI3t CONSTRAINT O=e#,7 C/EC@ FtyO#de#ed J ,70% O#de#Date DateT)me% Re;6)#edDate DateT)me% CONSTRAINT C@_Date C/EC@ Re;6)#edDate J O#de#Date00
Hs ally a si$'le ta&le de!i$itio$ #o ld provide cla ses !or 0ey de!i$itio$, i$de.i$', a$d other eleme$ts that have &ee$ le!t o t o! the previo s de!i$itio$ to !oc s i$ more closely o$ the se o! C1ECD co$strai$ts. *s yo ca$ see, co$strai$ts come i$ all shapes a$d si(es, co$trolli$' ta&le co$te$t, i$ter8ta&le relatio$ships, a$d validity o! data. *ltho 'h #e have disc ssed ma$y o&4ects, there are a !e# loose e$ds to tie p i$ order to 'et a ! ll perspective o$ o&4ects.

-ther /its and Pieces


There are ma$y di!!ere$t o&4ects #ithi$ a data&ase a$d s rro $di$' the ta&le co$te$t. * !e# o&4ects le!t to disc ss are rather speciali(ed i$ their se a$d i$ #here they are applied. /ermissio$s B#hich #e #ill leave $til Chapter =C are a #ide array o! ri'hts a$d privile'es that are prese$t at several levels, !rom the server to the data&ase to the ta&le, all the #ay do#$ to a$ i$divid al col m$. There are also pac0a'es that co$tai$ de!i$itio$s o! proced res sed &y DTS to 'et data !rom o$e place to a$other BDTS pac0a'es are disc ssed i$ Chapter 5, J)etrievi$' a$d Modi!yi$' DataJC. Alerts, operators, a$d jobs #or0 to'ether to aid i$ admi$istratio$ over the server &y allo#i$' !or the modi!icatio$ o! tas0s a$d i$!ormi$' i$divid als o! importa$t eve$ts o$ the server. These, alo$' #ith articles, p &licatio$s, a$d s &scriptio$s, are de!i$ed i$ the $e.t chapter, J*dva$ced /hysical Data&ase +mpleme$tatio$.J The o$ly o&4ect le!t $de!i$ed !rom a data perspective is tri''ers. Trigger #tili0ation Tri''ers are li0e stored proced res i$ that they co$tai$ a set o! T8S"% stateme$ts saved !or ! t re e.ec tio$. The &i' di!!ere$ce is that, $li0e stored proced res, tri''ers are e.ec ted a tomatically &ased o$ data activity i$ a ta&le. * tri''er may !ire &ased o$ ?9DATE, INSERT, or DELETE operatio$s. +$ S"% Server 2000, tri''ers ca$ &e !ired after a$ operatio$ completes BS"% Server de!a ltC or instead of the tri''eri$' operatio$. *$ A&TER tri''er ca$ &e sed to archive data #he$ it is deleted, to se$d a $oti!icatio$ that the $e# data has &ee$ added or cha$'ed, or to i$itiate a$y other process yo mi'ht #a$t to a tomate &ased o$ data activity. *$ INSTEAD O& tri''er ca$ &e sed to per!orm more adva$ced activities Bs ch as adva$ced data chec0i$'C, to e$a&le pdates i$ a vie# to occ r across m ltiple ta&les, a$d to per!orm ma$y other ! $ctio$s that mi'ht &e $ecessary i$ place o! a tri''eri$' activity. Tri''ers represe$t a mecha$ism i$ #hich code ca$ &e e.ec ted &ased o$ activity i$ the data. Tri''ers are e.pa$ded o$ a$d ! lly ill strated i$ Chapter :. Troubleshooting ailed -b1ect !reation Tro &leshooti$' is certai$ly a &road topic i$ the real developme$t #orld, a$d certai$ly o$ all Microso!t e.ams. +$ this chapter the !oc s !or tro &leshooti$' is o$ the i$teractio$s #ith o&4ects a$d the server, as #ell as applicatio$ setti$'s that are re5 ired !or a$ o&4ect to &e created a$d sed. 3$ the e.am tro &leshooti$' #ill &e approached !rom a #ide variety o! a$'les. +$ the Jreal #orldJ it is 'ood practice to al#ays vie# a proced re !rom a pro&lem8solvi$' perspective. *l#ays &e ready to as0 yo rsel!, J7hat co ld 'o #ro$'KJ a$d J7hat ca$ &e do$e to resolve the pro&lemKJ Most pro&lems associated #ith creati$' a$d2or accessi$' o&4ects ca$ &e resolved thro 'h setti$' appropriate o&4ect access permissio$s. 1o#ever, other eleme$ts that ca$ hamper the creatio$ or se o! o&4ects i$cl de B& t are $ot limited toC the !ollo#i$':

Bac0 p a$d restore operatio$s 3ther sers6 operatio$s loc0i$' parts o! the system 1ard#are or reso rce pro&lems Net#or0 co$$ectivity Co$!i' ratio$ setti$'s 3perati$' system Metadata corr ptio$

* 'ood starti$' poi$t !rom #hich to resolve most pro&lems is the #ealth o! !eed&ac0 S"% Server 'ives i$ the !orm o! the 3S *pplicatio$ Eve$t %o', S"% Server %o's, a$d the C rre$t *ctivity 7i$do#, as #ell as the permissio$ properties o! the sers, roles, a$d o&4ects. To create a data&ase, yo $eed to &e a mem&er o! System *dmi$istrators or Data&ase Creators server roles or have the Create Data&ase permissio$. To create o&4ects #ithi$ a data&ase, yo m st &e a mem&er o! db_ow3e# or db_ddladm)3 data&ase roles or have the speci!ic permissio$ to create the o&4ect as 'ive$ &y stateme$t8level permissio$s. Stateme$t8level permissio$s ca$ &e !o $d o$ the /ermissio$s ta& o! the data&ase /roperties dialo' &o.. *s data&ases a$d their o&4ects are created, the system ses the de!a lt !ile'ro p !or the physical stora'e o! the eleme$t. +t is a 'ood practice to create a stora'e 'ro p !or ser o&4ects a$d ma0e that the de!a lt !ile'ro p. This #ay, as the ser creates o&4ects, those o&4ects do$6t compete !or stora'e #ith other data. +! a ser lac0s the permissio$ to create or alter a$ o&4ect, a$ alter$ative is availa&le that 'ra$ts the ser creatio$ permissio$ #itho t 'ivi$' the ser too m ch co$trol over the e$viro$me$t. *$ *pplicatio$ role that has permissio$ to #or0 #ith o&4ects i$ this ma$$er ca$ &e assi'$ed to a stored proced re that creates the o&4ects !or the ser. 7he$ the ser e.ec tes the proced re, o&4ects ca$ &e created or altered i$ a co$trolled ma$$er. *'am Prep Questions

1.

*s a developer !or a lar'e healthcare provider, yo are assi'$ed the tas0 o! developi$' a process !or pdati$' a patie$t data&ase. 7he$ a patie$t is tra$s!erred !rom o$e !loor to a$other, a$ i$ter$al ide$ti!ier, C6##e3tRoomID, #hich is sed as the primary 0ey, $eeds to &e altered #hile the ori'i$al 0ey, Adm)tta3*eRoomID, is mai$tai$ed. +! a patie$t is moved more tha$ o$ce, o$ly the ori'i$al 0ey a$d the c rre$t 0ey $eed to &e mai$tai$ed. Several $derlyi$' ta&les have &ee$ co$!i' red !or re!ere$tial i$te'rity a'ai$st the patie$t ta&le. These $derlyi$' ta&les m st cha$'e i$ a$ appropriate ma$$er to match #ith o$e or the other o! the room 0eys i$ the patie$t ta&le. These relatio$ships #ill &e altered &ased o$ di!!ere$t sit atio$s i$ other ta&les. -i' re A.5 ill strates the 9at)e3tT#a*He# ta&le desi'$ e.hi&it. 7hat method #o ld yo se to accommodate the pdateK

-i' re A.5 The /atie$tTrac0er ta&le desi'$ e.hi&it. *. B. Hse the Cascade Hpdate )elated -ields optio$ to have cha$'es i$ the primary 0ey a tomatically pdate the 0eys i$ all re!ere$ced ta&les. Hse a$ i$de.ed vie# to e$a&le the ser to ma0e cha$'es to m ltiple ta&les co$c rre$tly. Disa&le the E$!orce )elatio$ship !or +$serts a$d Deletes optio$ to e$a&le a$ A&TER TRI--ER to ha$dle the $ecessary cha$'es. De!i$e a$ INSTEAD O& ?9DATE TRI--ER to per!orm the $ecessary pdates to all related ta&les.

C. D.

Ans*er: (. The INSTEAD O& tri''er #as desi'$ed speci!ically !or this type o! sit atio$ a$d also to ha$dle complicated pdates i$ #hich col m$s are de!i$ed as T)mestam1, Cal*6lated, or Ide3t)ty. Cascade operatio$s are i$appropriate &eca se the pdated 0ey is $ot al#ays stored. +$de.ed vie#s &y themselves do $ot allo# !or the type o! alteratio$ desired a$d #o ld have to &e compleme$ted #ith the actio$s o! a tri''er. Disa&li$' re!ere$tial i$te'rity is a poor sol tio$ to a$y pro&lem, especially co$sideri$' the medical $at re o! this applicatio$ a$d the possi&le rami!icatio$s. -or more i$!ormatio$, see the earlier sectio$ JTri''er Htili(atio$.J 2. * lar'e or'a$i(atio$ $eeds to mai$tai$ ima'e data o$ a data&ase server. The data is sca$$ed i$ !rom doc me$ts received !rom the !ederal 'over$me$t. Hpdates to the ima'es are i$!re5 e$t. 7he$ a cha$'e occ rs, s ally the old ro# o! data is archived o t o! the system a$d the $e# doc me$t ta0es its place. 3ther col m$ i$!ormatio$ that co$tai$s 0ey ide$ti!iers a&o t the $at re o! the doc me$t is !re5 e$tly 5 eried &y a$ 3%*/ system. Statistical i$!ormatio$ o$ ho# the data #as 5 eried is also stored i$ additio$al col m$s. The act al doc me$t itsel! is rarely $eeded e.cept i$ processes that pri$t the ima'e. 7hich o! the !ollo#i$' represe$ts a$ appropriate stora'e co$!i' ratio$K *. /lace the ima'e data i$to a !ile'ro p o! its o#$, & t o$ the same vol me as the remai$der o! the data. /lace the lo' o$to a vol me o! its o#$. B. /lace all the data o$to o$e vol me i$ a si$'le !ile. Co$!i' re the vol me as a )*+D parity set a$d place the lo' i$to a vol me o! its o#$.

C. D.

/lace the ima'e o$to o$e vol me i$ a !ile o! its o#$ a$d place the data a$d lo' !iles to'ether o$ a seco$d vol me. /lace the ima'e i$to a separate !ile'ro p #ith the lo' o$ o$e vol me a$d the remai$der o! the data o$ a seco$d vol me.

Ans*er: (. Beca se the ima'e data #ill seldom &e accessed, it ma0es se$se to 'et the remai$der o! the data a#ay !rom the ima'es #hile movi$' the lo' a#ay !rom the data. This #ill help to improve per!orma$ce #hile providi$' optim m recovera&ility i$ the eve$t o! a !ail re. -or more i$!ormatio$, see JThe -ile System.J

A.

*$ +$ter$et compa$y sells o tdoor hard#are o$li$e to more tha$ 100,000 clie$ts i$ vario s areas o! the 'lo&e. Servici$' the #e&site is a S"% Server #hose per!orma$ce is &arely ade5 ate to meet the $eeds o! the site. Eo #o ld li0e to apply a & si$ess r le to the e.isti$' system that #ill limit the o tsta$di$' &ala$ce o! each c stomer. The o tsta$di$' &ala$ce is mai$tai$ed as a de$ormali(ed col m$ #ithi$ the c stomer ta&le. 3rders are collected i$ a seco$d ta&le co$tai$i$' a tri''er that pdates the c stomer &ala$ce &ased o$ INSERT, ?9DATE, a$d DELETE activity. Hp to this poi$t, care has &ee$ ta0e$ to remove a$y data !rom the ta&le i! the clie$t &ala$ce is too hi'h, so all data sho ld meet the re5 ireme$ts o! yo r $e# process. 1o# #o ld yo apply the $e# data chec0K *. Modi!y the e.isti$' tri''er so that a$ order that allo#s the &ala$ce to e.ceed the limit is $ot permitted. B. Create a chec0 co$strai$t #ith the No Chec0 optio$ e$a&led o$ the c stomer ta&le, so that a$y i$appropriate order is re! sed. Create a r le that does$Lt permit a$ order that e.ceeds the limit a$d &i$d the r le to the 3rders ta&le. Create a $e# tri''er o$ the 3rders ta&le that re! ses a$ order that ca ses the &ala$ce to e.ceed the ma.im m. *pply the $e# tri''er to o$ly INSERT a$d ?9DATE operatio$s.

C.

D.

Ans*er: A. Beca se a tri''er is already i$ place, it ca$ easily &e altered to per!orm the additio$al data chec0. * r le ca$$ot provide the re5 ired ! $ctio$ality &eca se yo ca$$ot compare the data. The C/EC@ co$strai$t may &e a via&le sol tio$ & t yo #o ld have to alter the tri''er to chec0 !or a$ error a$d provide !or $ested operatio$s. The $ m&er o! tri''ers !iri$' sho ld &e 0ept to a mi$im m. To accommodate additio$al tri''ers, yo #o ld have to chec0 the order i$ #hich they are &ei$' !ired a$d a'ai$ set properties o! the server a$d data&ase accordi$'ly. -or more i$!ormatio$, see JTri''er Htili(atio$.J ;. *$ e.isti$' sales catalo' data&ase str ct re e.ists o$ a system #ithi$ yo r compa$y. The compa$y sells i$ve$tory !rom a si$'le #areho se locatio$ that is across to#$ !rom #here the comp ter systems are located. The prod ct ta&le has &ee$ created #ith a $o$8cl stered i$de. &ased o$ the prod ct +D, #hich is also the /rimary Dey. No$8cl stered i$de.es e.ist o$ the prod ct cate'ory col m$ a$d also the stora'e locatio$ col m$. Most o! the reporti$' do$e is ordered &y prod ct cate'ory. 1o# #o ld yo cha$'e the e.isti$' i$de. str ct reK *. Cha$'e the de!i$itio$ o! the /rimary Dey so that it is a cl stered i$de.. B. C. D. Create a $e# cl stered i$de. &ased o$ the com&i$atio$ o! stora'e locatio$ a$d prod ct cate'ory. Cha$'e the de!i$itio$ o! the prod ct cate'ory so that it is a cl stered i$de.. Cha$'e the de!i$itio$ o! the stora'e locatio$ so that it is a cl stered i$de..

Ans*er: (. Beca se the ma4ority o! the reporti$' is 'oi$' to &e per!ormed si$' the stora'e locatio$, it #o ld &e the li0ely ca$didate. The cl stered i$de. represe$ts the physical order o! the data a$d #o ld mi$imi(e sorti$' operatio$s #he$ derivi$' the o tp t. -or more i$!ormatio$, see JMai$tai$i$' 3rder #ith +$de.es.J 5. Eo are desi'$i$' a$ applicatio$ that #ill provide data e$try cler0s the capa&ility o! pdati$' the data i$ several ta&les. Eo #o ld li0e to ease e$try a$d provide commo$ i$p t so the cler0s $eed $ot e$ter data i$to all !ields or e$ter red $da$t val es. 7hat types o! tech$olo'ies co ld yo se to mi$imi(e the amo $t o! i$p t $eededK Select all that apply. *. -orei'$ 0ey B. Cascadi$' pdate m$

C. Ide3t)ty col
D. De!a lt

E. N?LL
-. /rimary 0ey

,. H$i5 e i$de.

Ans*er: +, C, (, !. *ll these optio$s have activities that provide or alter data so that it does $ot have to &e per!ormed as a$ e$try operatio$. +$ the case o! N?LL, data $eed $ot &e provided, possi&ly &eca se the col m$ co$tai$s $o$8critical i$!ormatio$. -or more i$!ormatio$, see JDeys to S ccess.J :. * data&ase that yo are #or0i$' o$ is e.perie$ci$' red ced per!orma$ce. The data&ase is sed almost e.cl sively !or reporti$', #ith a lar'e $ m&er o! i$serts occ rri$' o$ a re' lar &asis. Data is cycled o t o! the system !o r times a year as part o! 5 arter8e$di$' proced res. +t is al#ays importa$t to &e a&le to attai$ a poi$t8i$8time restoratio$ process. Eo #o ld li0e to mi$imi(e the mai$te$a$ce $eeded to accommodate i$creases a$d decreases i$ !ile stora'e space. 7hich optio$ #o ld assist the most i$ accomplishi$' the tas0K

*. SIM9LE RECOBER: B. A?TOS/RIN@ C. MAXSIZE D. A?TO-RO. E. COLLATE


Ans*er: (. Hse A?TO-RO. to set the system so that the !iles #ill 'ro# as $eeded !or the additio$ o! $e# data. Eo may #a$t to per!orm a pla$$ed shri$0a'e o! the data&ase as part o! the 5 arter8e$di$' process a$d save o$ overhead &y leavi$' the A?TOS/RIN@ optio$ t r$ed o!!. -or more i$!ormatio$, see JCreati$' -iles a$d -ile'ro ps.J

?.

Eo are the admi$istrator o! a S"% Server 2000 comp ter. The server co$tai$s a data&ase $amed +$ve$tory. Hsers report that several stora'e locatio$s i$ the ?3)tsSto#ed !ield co$tai$ $e'ative $ m&ers. Eo e.ami$e the data&aseLs ta&le str ct re. Eo correct all the $e'ative $ m&ers i$ the ta&le. Eo m st preve$t the data&ase !rom stori$' $e'ative $ m&ers. Eo also #a$t to mi$imi(e se o! server reso rces a$d physical +23. 7hich stateme$t sho ld yo e.ec teK

A. B. C. D. E. &. -. /. I. P. @. L. M. N. O. 9. F. R. S. T.

ALTER TABLE dbo.Sto#ageLo*at)o3s ADD CONSTRAINTC@_Sto#ageLo*at)o3s_ ?3)tsSto#edC/EC@ ?3)tsSto#ed J! 70 CREATE TRI--ER C@_?3)tsSto#ed O3 _ Sto#ageLo*at)o3s &OR INSERT% ?9DATE AS I& INSERTED.?3)tsSto#ed L 7 ROLLBAC@ TRAN CREATER?LE C@_?3)tsSto#ed As O?3)ts J! 7 -O s1_b)3d#6le QC@_?3)tsSto#edQQ_ Sto#ageLo*at)o3s.?3)tsSto#edQ -O CREATE 9ROC ?1date?3)tsSto#ed OSto#ageLo*at)o3ID_ )3t% O?3)tsSto#ed b)g)3t0 AS I& O?3)tsSto#ed L 7 RAISERROR ,77MM% +G0 ELSE ?9DATE Sto#ageLo*at)o3s SET ?3)tsSto#ed ! O?3)tsSto#ed ./ERE Sto#ageLo*at)o3ID ! OSto#ageLo*at)o3ID

Ans*er: A. Eo $eed to add a co$strai$t to preve$t $e'ative data e$try. The &est method o! impleme$ti$' this ! $ctio$ality is a co$strai$t. * tri''er has too m ch overhead a$d the R?LE is $ot acc rately impleme$ted. * proced re co ld ha$dle the process & t is $ormally sed o$ly !or processes re5 iri$' more comple. lo'ic. -or more i$!ormatio$, see J7hatLs o$ the Ta&le.J

<.

Eo are the admi$istrator o! a S"% Server 2000 comp ter. The server co$tai$s a data&ase $amed +$ve$tory. +$ this data&ase, the 9a#ts ta&le has a primary 0ey that is sed to ide$ti!y each part stored i$ the compa$yLs #areho se. Each part has a $i5 e H/C code that yo r compa$yLs acco $ti$' departme$t ses to ide$ti!y it. Eo #a$t to mai$tai$ the re!ere$tial i$te'rity &et#ee$ the 9a#ts ta&le a$d the O#de#Deta)ls ta&le. Eo #a$t to mi$imi(e the amo $t o! physical +23 sed #ithi$ the data&ase. 7hich t#o T8S"% stateme$ts sho ld yo e.ec teK BEach correct a$s#er represe$ts part o! the sol tio$G choose t#o.C

*. CREATE ?NIF?E INDEX IX_?9C O3 9a#ts ?9C0 B. CREATE ?NIF?E INDEX IX_?9C O3 O#de#Deta)ls ?9C0
C. CREATE TRI--ER ?9CRI O3 O#de#Deta)ls _ D. &OR INSERT% ?9DATE As

E. If Not E5)sts Sele*t ?9C &#om 9a#ts &. .2e#e 9a#ts.?9C ! )3se#ted.?9C0 -. BE-IN /. ROLLBAC@ TRAN I. END P. CREATE TRI--ER ?9CRI O3 9a#ts &OR INSERT% ?9DATE As @. If Not E5)sts Sele*t ?9C &#om 9a#ts L. .2e#e O#de#Deta)ls.?9C ! )3se#ted.?9C0 M. BE-IN N. ROLLBAC@ TRAN O. END 9. ALTER TABLE dbo.O#de#Deta)ls F. ADD CONSTRAINT&@_O#de#Deta)ls_9a#ts _ R. &OREI-N @E: ?9C0RE&ERENCES dbo.9a#ts ?9C0 S. ALTER TABLE dbo.9a#ts T. ADD CONSTRAINT&@_9a#ts_O#de#Deta)ls ?. &OREI-N @E: ?9C0RE&ERENCES dbo.9a#ts ?9C0
Ans*er: A, !. The ?NIF?E co$strai$t o$ the 9a#ts ta&le H/C col m$ is re5 ired !irst so that the &OREI-N @E: co$strai$t ca$ &e applied !rom the O#de#Deta)ls.?9C col m$ re!ere$ci$' 9a#ts.?9C. This achieves the re!ere$tial i$te'rity re5 ireme$t. +t also red ces +23 re5 ired d ri$' 4oi$s &et#ee$ 9a#ts a$d O#de#Deta)ls, #hich ma0e se o! the &OREI-N @E: co$strai$t de!i$ed. -or more i$!ormatio$, see J&OREI-N @E: Co$strai$t.J =. Eo are the data&ase developer !or a leasi$' compa$y. Eo r data&ase i$cl des a ta&le that is de!i$ed as sho#$ here:

+7. ++. +<. +K. +E. +,. +N.

CREATE TABLE Lease Id I3t IDENTIT: NOT N?LL CONSTRAINT 1H_lesse_)d 9RIMAR: @E: NONCL?STERED% Last3ame =a#*2a# ,70 NOT N?LL% &)#stName =a#*2a# ,70 NOT N?LL% SSNo *2a# M0 NOT N?LL% Rat)3g *2a# +70 N?LL% L)m)t mo3ey N?LL0

Each SSNo m st &e $i5 e. Eo #a$t the data to &e physically stored i$ SSNo se5 e$ce. 7hich co$strai$t sho ld yo add to the SSNo col m$ o$ the Lease ta&leK

*. ?NIF?E CL?STERED co$strai$t B. ?NIF?E ?NCL?STERED co$strai$t C. 9RIMAR: @E: CL?STERED co$strai$t D. 9RIMAR: @E: ?NCL?STERED co$strai$t
Ans*er: A. To o&tai$ the physical stora'e se5 e$ce o! the data, yo m st se a cl stered co$strai$t or i$de.. *ltho 'h a primary 0ey #o ld also provide !or the level o! $i5 e$ess, it is $ot the desired 0ey !or this ta&le. 1?. Eo are & ildi$' a data&ase a$d yo #a$t to elimi$ate d plicate e$try a$d mi$imi(e data stora'e #herever possi&le. Eo #a$t to trac0 the !ollo#i$' i$!ormatio$ !or employees a$d ma$a'ers: !irst $ame, middle $ame, last $ame, employee ide$ti!icatio$ $ m&er, address, date o! hire, departme$t, salary, a$d $ame o! ma$a'er. 7hich ta&le desi'$ sho ld yo seK

A. B. C. D. E. &. -. /. I. P. @. L. M.

Table+' Em1ID% Mg#ID% &)#st3ame% M)ddle3ame% Last3ame% Add#ess% /)#edate% De1t% Sala#y. Table<' Mg#ID% &)#st3ame% M)ddle3ame% Last3ame Table+' Em1ID% &)#st3ame% M)ddle3ame% Last3ame% Add#ess% /)#edate% De1t% Sala#y. Table<' Mg#ID% &)#st3ame% M)ddle3ame% Last3ame. _ TableK' Em1ID% Mg#ID Table+' Em1ID% Mg#ID% &)#st3ame% M)ddle3ame% _ Last3ame% Add#ess% /)#edate% De1t% Sala#y Table+' Em1ID% &)#st3ame% M)ddle3ame% Last3ame% Add#ess% /)#edate% De1t% Sala#y. Table<' Em1ID% Mg#ID TableK' Mg#ID

Ans*er: C. * si$'le ta&le co ld provide all the $ecessary i$!ormatio$ #ith $o red $da$cy. The ta&le co ld easily &e represe$ted si$' a sel!84oi$ operatio$ to provide the desired reporti$'. Moi$ operatio$s are disc ssed i$ detail i$ the Chapter 5.

1<. Eo are developi$' a$ applicatio$ a$d $eed to create a$ i$ve$tory ta&le o$ each o! the data&ases located i$ Ne# Eor0, Detroit, /aris, %o$do$, %os *$'eles, a$d 1o$' Do$'. To accommodate a distri& ted e$viro$me$t, yo m st e$s re that each ro# e$tered i$to the i$ve$tory ta&le is $i5 e across all locatio$s. 1o# ca$ yo create the i$ve$tory ta&leK *. S pply Ide3t)ty col m$s si$' a di!!ere$t se5 e$tial starti$' val e !or each locatio$ a$d se a$ i$creme$t o! :.

B. C. D.

Hse the IDENTIT: ! $ctio$. *t the !irst locatio$ se IDENTIT: +%+0, at the seco$d locatio$ se IDENTIT: +77777%+0, a$d so o$. Hse a ?NIF?EIDENTI&IER as the 0ey at each locatio$. Hse the T)mestam1 col m$ as the 0ey at each locatio$.

Ans*er: A. Hsi$' ide$tities i$ this !ashio$ e$a&les records to &e e$tered that have $o overlap. 3$e locatio$ #o ld se e$try val es 1, ?, 1A, 1=G the $e.t #o ld have 2, <, 1;, 20G the third, A, =, 15, 21G a$d so o$. -or more i$!ormatio$, see JData Eleme$t De!i$itio$.J 1=. Eo are & ildi$' a $e# data&ase !or a compa$y #ith 10 departme$ts. Each departme$t co$tai$s m ltiple employees. +$ additio$, each employee mi'ht #or0 !or several departme$ts. 1o# sho ld yo lo'ically model the relatio$ship &et#ee$ the departme$t e$tity a$d the employee e$tityK *. Create a ma$datory o$e8to8ma$y relatio$ship &et#ee$ departme$t a$d employee. B. C. Create a$ optio$al o$e8to8ma$y relatio$ship &et#ee$ departme$t a$d employee. Create a $e# e$try, create a o$e8to8ma$y relatio$ship !rom the employee to the $e# e$try, a$d create a o$e8to8 ma$y relatio$ship !rom the departme$t e$try to the $e# e$try. Create a $e# e$try, create a o$e8to8ma$y relatio$ship !rom the $e# e$try to the employee e$try, a$d the$ create a o$e8to8ma$y relatio$ship !rom the e$try to the departme$t e$try.

D.

Ans*er: C. This is a ma$y8to8ma$y relatio$ship sce$ario, #hich i$ S"% Server is impleme$ted si$' three ta&les. The ce$ter ta&le, o!te$ re!erred to as the co$$ecti$' or 4oi$i$' ta&le, is o$ the ma$y side o! &oth o! the relatio$ships to the other &ase ta&le. -or more i$!ormatio$, see J&OREI-N @E: Co$strai$t.J
N 200: /earso$ Ed catio$, +$c. +$!ormit. *ll ri'hts reserved. <00 East =:th Street +$dia$apolis, +$dia$a ;:2;0

You might also like