TransformationRule(逻辑实现成关系表的规则)

来源:互联网 发布:机加工工艺软件 编辑:程序博客网 时间:2024/06/09 23:03
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

wordunderlinedisprimarykey
Rule1.EachentityinanE-Rdiagramismappedtoasingletableinarelationaldatabase;thetableisnameaftertheentity.Thecolumnsofthetablerepresentallthesingle-valuedsimpleattributesthatareattachedtotheentity(possiblythroughacompositeattribute,althoughacompositeattributeitsselfdoesnotbecomeacolumnofthetable)。

Rule2:GivenanentityEwithprimaryidentifierp,amulti-valuedattributeaattachedtoEinanE-Rdiagramismappedtoatableofitsown;thetableisnamedafterthepluralmulti-valuedattribute.Thecolumnsofthisnewtablearenamedafterpanda,androwsofthetablecorrespondto(p,a)valuepairs,representingallpairingsofattributevaluesofaassociatedwithentityoccurrencesinE.Theprimarykeyattributeforthistableisthesetofcolumnsinpanda.
EG:(herep==eid,a==hobby)
employes(eid,staddress,city,states,zipcodes)(197,7Beacon,Boston,MA,02102)(221,19BrightonSt,Boston,MA,02103)
hobbies(eid,hobby)(197,chess)(197,painting)(221,reading)

Rules3:N-NRelationships.WhentwoentitiesEandFtakepartinamany-to-manybinaryrelationshipR,therelationshipismappedtoarepresentativetableTintherelatedrelationaldatabasedesign.ThetablecontainscolumnsforallarrtibutesintheprimarykeysofbothtablestransformedfromentitiesEandF,andthissetofcolumnsformstheprimarykeyforthetableT.
EG:(Employees-(1,N)-works_on-(0,N)-Projects        ---N-N(many-to-many) )
employees(eid,straddr,city,state,zipcode) --woks_on(eid,prid,percent)--projects(prid,proj_name,due_date)

Rules4:N-1Relationships.WhentwoentitiesEandFtakepartinamany-to-onebinaryrelationshipR,therlationshipwillnotbemappedtoatableofitsowninarelationaldatabasedesign.Instead,ifweassumethattheentityFhasmax-card(F,R)=1andthusrepresentsthe“many“sideoftherelationship,therelationaltableTtransformedfromtheentityFshouldincludecolumsconstituting theprimarykeyforthetabletransformedfromtheentityE;thisisknownasaforeignkeyinT.
EG:instructors(insid,lname,office_no,ext) --cours_sections(secid,insid,course,room,preriod).

Rules5:1-1Relationships,optionalParticipation.GiventwoentitiesEandFthattakepartinaone-to-onebinaryrelationshipR,whereparticipationisoptionaloneitherside,wewishtotranslatethissituationintoarelaionaldesign --Useforeignkeyoneitherorbothsides.

Rules6:1-1Relationships,MandatoryParticipationonBothSides.Inthecaseofaone-to-onerelationshipwithmandatoryparticpationonbothsides,itis mostappropriateto combinethetablesforthetwoentitiesintoone,andinthiswayavoidanyforeignkeys. 

 

 

 

 

 

 

 

 

 

 
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>