SVY200: Databases for GIS Lecture 0: From ER & EER odels to Relation Scheme. Dr Stuart Barr School of Civil Engineering & Geosciences University of Newcastle upon Tyne. Email: S.L.Barr@ncl.ac.uk Lecture 0: ER & EER to Relation Scheme
Lecture Objectives & Contents Objectives: To consider how to transform ER and EER models to relation scheme and mappings. Contents: ER model to relation scheme. EER model to relation scheme considerations. Summary Lecture 0: ER & EER to Relation Scheme 2
E/R to Relation Scheme & apping How do we move from this to relation scheme? SattfID Address Sex Hours Income Work_On N Project Controls anages Work_For Department StDate DeptID Lecture 0: ER & EER to Relation Scheme 3
apping Regular Entity Sets ake regular (normal) entity sets in an ER model a simple relation in the relational scheme. Include all normal attributes & choose an entity key to be the primary key. ID Address Sex ID Address Sex Lecture 0: ER & EER to Relation Scheme 4
apping Weak Entity Sets Create a relation for the weak entity set. Its foreign key = the primary key of the identifying entity set. Its primary key = partial key + primary key of identifying entity set. DoB Relation ID Dependent DependentOf Dependent ID DoB Relation Lecture 0: ER & EER to Relation Scheme 5
Binary One-to-One Relationships ake sure that the two entity sets have been mapped to relations. The preferred approach is then to cerate an explicit One-to-One relationship on the basis of the primary and foreign key concept. Can also merge a relations or create a relationship relation. ID Address Sex DeptID anages Department ID Address Sex Department DeptID anagerid Lecture 0: ER & EER to Relation Scheme 6
Binary One-to-any Relationships Find the any entity-set (relation) of the relationship. Include in this relation as a foreign key the primary key of other entity set (relation) in the relationship. An alternative again is the relationship relation. ID Address Sex DeptID WorkFor Department ID Address DeptID Sex Department DeptID anagerid Lecture 0: ER & EER to Relation Scheme 7
Binary any-to-any Relationships Needs a new relation that acts as a lookup - so must have a relationship relation. The foreign keys are the primary keys of the two participating entity sets (relations). The primary key of the relationship relation is both foreign keys. ID Address Sex Income Work_On N Project ID Address Sex Proj ID Proj Project Income Lecture 0: ER & EER to Relation Scheme 8
N-ary Relationships Create a new relation to represent the N-ary relationship. Foreign keys are the primary keys of the defining relations. Its primary key is the combination of primary keys of the relations. ID Address Sex Cost Prefer N Instruments Income Project ID Address Sex Instrument cost ProjIns ID Instru Proj Project Income Lecture 0: ER & EER to Relation Scheme 9
ultivalued Attributes Will violate first-normal form. Create a new relation whose for foreign key is the primary key of the entity set. The primary key of the new relation is foreign key and the attribute name given to the multivalued attribute. The relationship between the two relations is a One-to-any. Number Locations Department Department Number Dept_Locations Number Location Lecture 0: ER & EER to Relation Scheme 0
Relationship Attributes: any-to-any They simply form an attribute of the relationship relation that is created. SattfID Address Sex Hours Income Work_On N Project ID Address Sex Proj ID Proj Hours Project Income Lecture 0: ER & EER to Relation Scheme
Relationship Attributes: One-to-One & One-to-any Best managed by incorporating into one of the base relations. Choose the relation where the attribute will not have a null item. ID Address Sex DeptID StDate anages Department ID Address Sex Department DeptID anagerid anagerstdate Lecture 0: ER & EER to Relation Scheme 2
EER odel apping option ultiple relations for superclass & subclass. Works for any specialisation (total/partial & disjoint/overlap). ID Address Sex Qualification TypeSpeed Surveyor Technician Secretary Instrument ID Address Sex Secretary ID Qualification Technician ID Qualification Surveyor ID Qualification Lecture 0: ER & EER to Relation Scheme 3
EER odel apping option 2 ultiple relations for subclasses. Only for subclasses that give total specialisation. Reg Price Vehicle NPassengers Speed Car Truck Tonnage Nwheels Car Reg Price NPassengers speed Truck Reg Price Tonnage Nwheels Lecture 0: ER & EER to Relation Scheme 4
EER odel apping option 3 Single relation with a distinctive (discriminating) type attribute. Works only for subclasses that are disjoint. Null values and large degree tuples potential problem. ID Address Sex Qualification TypeSpeed Surveyor Technician Secretary Instrument ID Address JobType Qualification TypeSpeed Instrument Sex Lecture 0: ER & EER to Relation Scheme 5
EER odel apping option 4 Single relation with Boolean flags to recognise subclass type. Works for specialisation that have overlapping subclasses. Again potential for large number of nulls and large tuple degree. ID Address Sex Project O odules Researcher Lecturer ID Address Sex RFlag Project Lflag odule ID oduleid odule oduleid Lecture 0: ER & EER to Relation Scheme 6
EER odel apping: ultiple Inheritance Can be handled using all the previous options. Choice depends on trade off between excessive relations Vs large tuples with lost of nulls. Surveyor anager Survey_anager ID. Surveyor ID anager ID Survey_anager ID Lecture 0: ER & EER to Relation Scheme 7
EER odel apping: Union Types Superclasses have different keys neither can identify the union. Specify a new key attribute called a surrogate key to build relationship with union class. Company U Person Users Subscribe Company CID UserID. Person NI UserID. Users UserID Subscribe UserID agid Lecture 0: ER & EER to Relation Scheme 8
Lecture 0: Reading Elmasri, R., and Navathe, S., 2003. Fundamentals of Database Systems. Addison Wesley (London). Pages 9-205. Lecture 0: ER & EER to Relation Scheme 9