Tải bản đầy đủ - 0 (trang)
Hack 11. Use a Junction Table

Hack 11. Use a Junction Table

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

InFigure1-24,thestudenttableisalsorequiredtohavethe

instructorIDastheforeignkey.Thisisacceptable,butnow

lookattheappointmentstable;itconsidersappointmentsas

belongingtostudents,butappointmentsbelongtoboth

instructorsandstudents.

Figure1-25showshowtoresolvethedilemmainthedata

model.Becauseappointmentsbelongtobothinstructorsand

students,thatishowthemodelshouldlook.Theappointments

tableservesasajunctiontablebetweeninstructorsand

students.

Ajunctiontablebecomesthemanytablefortwoormoreother

tables.Allthekeyfieldsoftheonetablesbecomeforeignkeys

inthejunctiontable.Anyotherpertinentfieldsareincludedin

thejunctiontable.Inthisexample,thejunctiontablehasfields

forthedateandtimetheinstructorandstudentwillmeet.Also,

thestudenttablenolongerhastheinstructorIDasaforeign

key.Inthisexample,instructorsandstudentshaveno

hierarchy;therefore,itmakessensethatonedoesn'tserveasa

manytotheother.



Figure1-25.Abettermodel



Hack12.StoptheDatabasefromGrowing



UsetheCompactonCloseoptiontokeepadatabasefrom

gettingtoobig.

Accessdatabasesarenotoriousfortheirabilitytogrowinsize.

Thisisespeciallytrueasdataismovedinandout.Forexample,

whenadatabaseapplicationregularlyimportsdata,processes

thedata,andthenexportsitbackout,thedatabasecan

becomehuge,ontheorderofseveralmegabytesinsize.This

canbethecaseevenwhenthedatamovinginandoutisofa

reasonablesize.

Toshrinkthedatabasebacktothesizeitshouldbe,youneed

tocompactthedatabase.However,expectinguserstocompact

theirdatabasesisn'tagreatidea,especiallyifyourusersaren't

technicallysavvy.Luckily,Accessincludesanoptiontocompact

adatabasewhenitisclosed.Thisoptionwasnotavailablein

olderversionsofAccess,butitisavailableinAccess2002and

Access2003.

Figure1-26showstheOptionsdialogbox(Tools Options)

withtheGeneraltabontop.NotetheCompactonClose

checkbox.

Accessisunlikeotherproducts,suchasSQLServer,inthatit

doesn'tallowyoutocontrolthesizeofthedatabase.Setting

thedatabasetocompacteachtimeitclosesremoveswhathas

traditionallybeenarecurringproblemwithAccess.



Figure1-26.Selectingtocompactonclose



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

Hack 11. Use a Junction Table

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

×