Tải bản đầy đủ - 0 (trang)
Chapter 6. Working with Multiple Tables

Chapter 6. Working with Multiple Tables

Tải bản đầy đủ - 0trang

MultitableSystemsinFileMakerPro

Chapter5,"RelationalDatabaseDesign,"laidaheavydoseof

abstractdatabasetheoryonyou.Thischaptershowsyouhow

totakethoseideasandusethemtobuildFileMakerdatabase

systems.You'lllearnhowtouseFileMakertocreatedatabase

systemsthatmodelthetypesofrelationshipscoveredin

Chapter5.Ingeneral,wedon'tliketoprescribealinearpath

throughthisbook,butforthischapter(andreallytheone

following,aswell),we'regoingtoassumethatyoueitherhave

readChapter5orhaveareasonablefamiliaritywiththeterms

andconceptsofrelationaldatabasedesign.Iftermssuchas

entity-relationshipdiagram,primarykey,foreignkey,andoneto-manyrelationshipareunfamiliartoyou,werecommendthat

youreviewChapter5beforeproceedinghere.

Chapter5laidoutasetofdesignconceptsthatcentered

aroundtheideasofentities,theirattributes,andthe

relationshipsbetweenentities.InFileMakerPro,you'llgenerally

representadatabaseentity("student,"forexample)asatable.

You'llgenerallyrepresentanentity'sattributes("firstname,"

"yearofgraduation,"forexample)bythefieldsofthattable.

Andyou'llcreaterelationshipsamongtableswithFileMaker's

RelationshipsGraph,atoolwe'llbeshowingyouinthischapter.

Beforeyougetintothemeatofthischapter,it'sagoodideato

reviewFileMaker'sdefaultbehaviorwhenyoucreateanew

database.Whenyoucreateanewdatabase,FileMakercreatesa

databasewithjustonetableinit,andthattableinitiallyhasthe

samenameasthenameyougavethedatabaseasawhole.

Thisisasensibledefaultbehaviorifyouonlyeverintendto

workwithonetableinthegivendatabase.

ButFileMakeralsohasfacilitiesforaddingmoretablestoa

system,addingdifferentfieldstoeachtable,andcreatingmany

kindsofrelationshipsbetweentables.Weexplorethesetoolsin



thecontextofsomeofthefundamentalrelationshiptypes

discussedinChapter5.







CreatingaOne-to-ManyRelationshipin

FileMaker

Let'sconsiderasimplecase.We'redoingadatabasefora

municipalgovernment.Thedatabaseisintendedtostore

informationonallthetownsinanarea,aswellasalistof

governmentofficialssuchasmayors,commissioners,andthe

like.IfwefollowtheprinciplesmentionedinChapter5andtry

tothinkofthisinentity-relationshipterms,itshouldbeclear

thatwehavetwodifferententitieshere:"town"and"town

official."Thetwohaveaone-to-manyrelationship:Onetown

mayhavemanyofficials.(We'llassumeforthesakeof

simplicitythatasinglepersoncan'tholdmorethanoneofficial

postatonce.)

Eachentityinanentity-relationshipdiagram(ERD)generally

translatesintoonetableinaFileMakersystem.Tomakethis

happenforourexample,beginbycreatingadatabasethat

initiallycontainsjusttheTowntable,andthenadda

TownOfficialtableandjointhetwoinarelationship.The

followingsectionsdescribehow.



CreatingtheFirstTableinaMultitableSystem

Again,whenyoucreateaFileMakerdatabaseforthefirsttime,

yougetasingletablewiththesamenameasthedatabase.If

youcreateanewdatabasecalledTown,you'llgetwithinita

singletable,alsocalledTown,andtheoptiontoaddfieldsto

thattable.Theinitialfielddefinitionmightlookasshownin

Figure6.1.



Figure6.1.Fielddefinitionsforaninitialtableina

databaseoftowninformation.



[Viewfullsizeimage]



We'vedefinedanumberofbasicfieldscontainingtown

information.Youshouldnoticetwothingshere.First,thereisa

fieldcalled__kp_TownID.Thatfieldwillbetheprimarykey

field,whichwillbeessentialwhenit'stimetobuilda

relationshiptoanothertable.Noticealsothesmallmenuatthe

upperleftoftheDefineDatabasedialogcalledTable.Ina

multitablesystem,thismenunamesthetableyou'recurrently

workingwith,andletsyouswitcheasilyamongfielddefinitions

fordifferenttables.

Forarefresheronthedetailsofcreatingfieldswithinasingletablein

FileMaker,seeChapter3,"WorkingwithFields,"p.69.



AddingaTabletoaMultitableSystem

ThattakescareoftheTowntable.Toaddatablefor

TownOfficer,stayintheDefineDatabasedialog,butswitchto

theTablestab.You'llseejustonetable,whichinthisexampleis

calledTown.Toaddanewtable,typethenameintheTable

NameboxandclickCreate,andthenewtablewillbeaddedto

thelist,asshowninFigure6.2.



Figure6.2.FileMaker'sTablesview,showinga

databasewithmultipletables.



[Viewfullsizeimage]



You'renowfreetoaddfieldstothenewtable.Figure6.3shows

asuggestedfieldlistfortheTownOfficertable.



Figure6.3.Fieldstructureforatableoftown

officers.



[Viewfullsizeimage]



Payattentiontotwofieldshere.Thefirstis

__kp_TownOfficerID.Like__kp_TownIDintheTowntable,this

istheprimarykeyforTownOfficer.Noticealsothefieldcalled

_kf_TownID.Thisistheforeignkeythatmakesitpossibleto

specifyinwhichtownthisparticulartownofficerserves.The

foreignkeywillbecrucialtomakingtherelationshipbacktothe

Towntable.Laterinthischapterwediscusstheprinciplesof

makingeffectivekeyfieldsinFileMaker.



Note

Youmightfindthenamingconventionusedherefor



keyfieldsabitpuzzling.Forprimarykeys,we

precedethefieldnamewithadoubleunderscore

(__),andthen"kp"tosignifyaprimarykey.For

foreignkeys,weprecedethefieldnamewitha

singleunderscoreandthedesignation"kf".The

effectofthisconventionistocauseallthekeyfields

tosorttothetopofanalphabetizedfieldlistin

FileMaker,andfurtherfortheprimarykeytosortto

theverytop,aboveallforeignkeys.Thismakesit

veryeasytoaccessthekeyswhenyou'rebuilding

relationshipsintheRelationshipsGraph.



Forarefresheronprimaryandforeignkeys,see"Understandingthe

RoleofKeysinDatabaseDesign,"p.143.



AddingaRelationship

Therearenowtwotables,aswellastheprimaryandforeign

keysthatgooddatabasedesigndemands.Tocreatea

relationshipbetweenthesetwotables,movetothe

RelationshipstaboftheDefineDatabasedialog.Thiswindow,

knownastheRelationshipsGraph,shouldhaveacoupleof

graphicalelementsalreadydisplayed.Eachonerepresentsone

ofthedatabasetablesthatexistinthisdatabase.These

elementsareknownastableoccurrences.Eachshowsthe

nameofthetableitrepresents,alongwiththattable'sfields.

Figure6.4showstheGraphwiththetwotablespresented

there.



Figure6.4.FileMaker'sRelationshipsGraph,with



tableoccurrencesfortwotables.



[Viewfullsizeimage]



Addingarelationshipbetweenthesetwotableoccurrencesis

simple:Positionthemouseoverthe__kp_TownIDfieldinthe

Towntableoccurrence,anddraguntilthemouseisoverthe

corresponding_kf_TownIDfieldintheTownOfficertable

occurrence.Youshouldseealineextendfromonetabletothe

other.Whenyoureleasethemouse,FileMakercreatesthe

relationshipanddisplaysitasalinkbetweenoneormore

matchfieldsatthetopofthetableoccurrencepair.Figure6.5

showshowtheGraphwilllookasaresult.



Figure6.5.FileMaker'sRelationshipsGraph,with

arelationshipbetweentwotableoccurrences.



[Viewfullsizeimage]



Youmighthavenoticedthe"crow's-foot"attheendofthe

relationshipline,whereittouchestheTownOfficertable

occurrence.Thisisnoneotherthantheindicatorthatyou're

accustomedtoseeingontheERDsfromtheprecedingchapter.

It'sintendedtoindicatethe"many"sideofaone-to-many

relationship.Bewarned,though!FileMakerprovidesthis

graphicaladornmentasakindofahintorguessaboutthe

relationshipitmaynotalwaysbeaccurate,thoughinthiscaseit

is.Weexplainthatpointfullyinthenextsection,wherewe

discussthecreationofkeyfieldsinFileMaker.

Atthispointyou'veseenhowtoaddanewtabletoFileMaker's

defaultone-tabledatabaseconfigurationandhowtodefinea

one-to-manyrelationshipbetweentwoFileMakertables.The

nextsectionsclarifysomeimportantpointsaboutmultitable

systems.



WorkingwithKeysandMatchFields

YoushouldrememberfromChapter5thatkeysaretable

fieldsfieldsthatareessentialelementsinformingtherelational

structureofamultitablesystem.FileMakertakesasomewhat

broaderviewofkeys,asyou'llsee,andforthatreasonthese

fieldsarereferredtoasmatchfieldswhenyou'reworkingina

FileMakercontext.AmatchfieldinFileMakerisanyfieldthat

participatesinarelationshipbetweentwoFileMakertables.

Primarykeysandforeignkeysfitthisdefinition,ofcourse,but

sodoanumberofothertypesoffieldsthatareexploredmore

inthenextchapter.

FormoreonthebroaderusesofmatchfieldsinFileMakerPro,see

"RelationshipsasQueries,"p.184,aswellasothersectionsofChapter

7,"WorkingwithRelationships."



Keyfields(whichformthestructuralbackboneofthesystem)

needtoplaybysomespecialrulesespeciallyprimarykeys.

Considerthecurrentexample,theTowndatabasesystem,and

considerthe__kp_TownIDfieldintheTowntable.Thisfieldhas

beenidentifiedastheprimarykeyfortheTowntable.Toplay

theroleofprimarykey,thereareafewrulesthefieldhasto

follow.Inthefirstplace,thevalueinithastobeuniquewithin

thegiventable.Intheexample,thismeansthatnotwotowns

shouldsharethesame__kp_TownID(thoughit'sfineifthere's

atownofficialwithanIDof27,aswellasatownwithanIDof

27they'reintwodifferenttables,soyouwon'tgetthemmixed

up).Thereasonsforthisarefairlyobvious:AtownIDisn't

muchuseiftwotownscanshareasingletownID;we'dhave

nowaytoidentifyonesingletownuniquely.Andbythesame

token,weneverwantthe__kp_TownIDfieldtobeempty.

FileMakerhelpsusworkwithintheseconstraints.



Tomakeafieldsuitableforuseasaprimarykey,use

FileMaker'sfieldoptionstoaddsomeimportantrestrictionsto

thefielddefinition.YoudothisintheOptionsdialogthat's

availablewhenyouhaveafieldselectedintheDefineDatabase

dialog.

OntheAuto-EntertaboftheOptionsdialog,clicktheSerial

Numbercheckbox(seeFigure6.6).(Leavethespecificserial

numberoptionsalonefornow.)ThisinstructsFileMakertoenter

anew,uniquenumberintothefieldeverytimearecordis

created,startingatwhatevernumberyouspecifyandgoingas

highasnecessary.



Figure6.6.Useaserialnumberingauto-entry

optiontopopulateaprimarykeyfield.



[Viewfullsizeimage]



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 6. Working with Multiple Tables

Tải bản đầy đủ ngay(0 tr)

×