# Section 1010 ER Problems and Styles1 HSQ - DATABASES & SQL And Franchise Colleges 10 ER Problems and Styles By MANSHA NAWAZ.

## Presentation on theme: "Section 1010 ER Problems and Styles1 HSQ - DATABASES & SQL And Franchise Colleges 10 ER Problems and Styles By MANSHA NAWAZ."— Presentation transcript:

Section 1010 ER Problems and Styles1 HSQ - DATABASES & SQL And Franchise Colleges 10 ER Problems and Styles By MANSHA NAWAZ

Section 1010 ER Problems and Styles2 Introduction: Recursive Relationships Entities may have relationships with themselves: The Enterprise Rule: –A component may be composed of 0,1,m other components –A component may be part of 0,1 components This is called a Recursive relationship. Component Is composed of m 1

Section 1010 ER Problems and Styles3 1:1 Recursive Relationships Enterprise rule: –A Twin has exactly one Twin. –The enterprise is the same in both directions. Twin Is the twin of 1 1 Very difficult - all other examples turn out to be twins of some kind. Can you think of another example? ?? 1 1

Section 1010 ER Problems and Styles4 1:1 Recursive Relationships - continued Another useful example Enterprise rule: –A Child has 0,1 Twins. –The enterprise rule is the same in both directions. Child Is the twin of 1 1 Operation Precedes / succeeds 1 1 Enterprise rule: An Operation has 0,1 Preceding Operations. An Operation has 0,1 Succeeding Operations. A linked list structure... These three examples are particularly useful as most 1:1 recursives are an example of one of these.

Section 1010 ER Problems and Styles5 1:m Recursive Relationships Can you see a problem with this? The boss has to manage themselves! Notice one ‘leg’ of the relationship has a role name. –This is very effective in making recursive relationships understandable. Enterprise rule: A employee manages 0,1,m employees A employee is managed by exactly 1 employee Employee Manages 1 m Manager

Section 1010 ER Problems and Styles6 1:m Recursive Relationships continued... Enterprise rule: A Major-component is composed of 0,1,m Minor-components A Minor-component is part of 0,1 Major-components Here we can see the advantage of roles names. Component Is part of 1 m Major-component Minor-component Many end with non-obligatory membership class.

Section 1010 ER Problems and Styles7 m:m Recursive Relationships Enterprise rule: A Major-component is composed of 0,1,m Minor-components A Minor-component is part of 0,1,m Major-components Decomposing... Component Is part of m m Major-component Minor-component What do we need to do with m:m relationships? Complex entity Component is 1 1 Major-component Minor-component in m Sub- Component m

Section 1010 ER Problems and Styles8 m:m Recursive Relationships continued... Remember that when you have a complex entity you need to determine: –Name, Attributes, Primary Key (Identifier), Description This may be much more difficult for a recursive complex entity. –However, the is composed of model above is quite useful generally. –Some possible versions of the above as table types. Sub-component(minor.component#, major.component#, quantity required,..) or... Sub-component(minor.component#, major.component#, assembly-sequence,..) Could the second one be used to represent written documents?? Component is 1 1 Major-component Minor-component in m Sub- Component m

Section 1010 ER Problems and Styles9 Connection Traps So far modelling looks very attractive. –A powerful tool based around a simple diagramming technique. –However, there are some pitfalls for database designers. –Generally these pitfalls are due to wrongly interpreting the meaning of relationships. –Poor design of complex entities usually results in significant connection trap problems. Careful design of complex entities, together with an approach of working outwards from complex (transactional) entities helps to eliminate connection trap problems. (Work back from the money! - see below) Cinema Film at 1 m Season of 1 m Showing in m 1

Section 1010 ER Problems and Styles10 Fan Traps In this version of the previous model can we: –Determine which Cinema and Film relates to a particular Showing? Can we: –Determine all the Showings in a particular Season? –Determine the Season for a particular Showing? We can: –Find the appropriate Cinema and Film for any Showing or Season. –We can only relate a Showing to all the Seasons in a particular Cinema. –We can only relate a Showing to all the Seasons for a particular Film. These are called Fan Traps. Cinema Film at 1 m Season of 1 m Showing in m 1 of m 1 Fan Trap

Section 1010 ER Problems and Styles11 Avoiding Fan Traps Does this version of the ERD avoid the previous problems? So significant fan traps can be avoided by re-designing the relationships. Again: Careful design of complex entities, together with an approach of working outwards from complex (transactional) entities helps to eliminate connection trap problems. (Work back from the money!) Cinema Film at 1 m Season of 1 m Showing in m 1

Section 1010 ER Problems and Styles12 Non-Significant Fan Traps Why don’t we care about the Fan Trap shown? Stars are related to all Seasons, Showings and Cinema where their Films are shown. All Seasons and Showings are related to all the Stars in the Film shown. It is not a trap at all. –These patterns often occur at the edges of ERDs. Film Cinema at 1 m Season of 1 m Showing in m 1 Non-Significant Fan Trap Star in m 1 Actor is 1 m

Section 1010 ER Problems and Styles13 Chasm Traps This looks reasonable but has some hidden problems. –We would assume we can always find the regiment a soldier is in. Regiment Soldier in m 1 Platoon in 1 m Soldier S4 S11 S3 S19 S9 S2 S6 Platoon P1 P2 P3 Regiment R1 R2 S2 is the Regimental Sergeant Major (not in a platoon) - which regiment is he in? –OOPS - you can tell him the system doesn’t know what regiment he is in…...

Section 1010 ER Problems and Styles14 Chasm Traps - Removing Usually such problems can be solved by re-designing the relationships or adding new relationships. The above solution, adding a new relationship, resolves this problem. –In another scenario a similar problem may be solved by just re-designing (swapping around) the relationships. Regiment Soldier m 1 Platoon in 1 m m1

Section 1010 ER Problems and Styles15 n All data model can be conveyed by Entity Relationship Diagram (ERD) n Commonly used structure is the NETWORK style ERD. n Good ERDs should also try and utilises the following styles. n This section covers popular style ERD STYLES

Section 1010 ER Problems and Styles16 HIERARCHY STYLE ERD LIVING CREATURE is a PERSON male type MALE FEMALE female type c#, cdesc c#

Section 1010 ER Problems and Styles17 SET TYPE EMPLOYEE TYPE emp_type Consider the entity employee and the following data set : EMPLOYER eno ename esalary etype e1 Smith 12klecturer e2 Jones 12k lectuere e3 Brown 7k dean e4 Green 10klecturer EMPLOYERemp_typeEMPLOYEE_TYPE eno ename esalary eno etypenoetypeno etype e1 Smith 12ke1 et1et1lecturer e2 Jones 12k e2 et1et2dean e3 Brown 7k e3 et2 e4 Green 10ke4 et1 EMPLOYEE We can ALSO map the above data into a set type ERD as follows :

Section 1010 ER Problems and Styles18 SET OPERATION MALE STAFF sex FEMALE ENGINEERING STAFF position BUSINESS STAFF S#, SNAME, SADDRESS, STEL S# S#, SNAME, SADDRESS, STEL S# UNION OBTAINED BY JOINING ALL DATA FROM SET TYPE TABLES. ie jjoin keys from MALE and FEMALE tables join keys from ENGINEERING and BUSINESS tables UNION = SET(A)+SET(B) INTERSECTION OBTAINED BY SELECTING DATA WHICH ONLY EXISTS IN ALL SET TYPE TABLES ie select all records which exist in both MALE and FEMALE tables select all records which exist in both ENGINEERING and BUSINESS tables INTERSECTION = SET(A)-SET(B) WE ARE THEREFORE ABLE TO USE SET THEORY TO OBTAIN SELECTIVE LISTS.

Section 1010 ER Problems and Styles19 SUB SET (decomposition) FULL PROFESSORS by rank ASSOCIATE PROFESSORS ASSISTANT PROFESSORS P#, PNAME, PADDRESS, PTEL P#

Section 1010 ER Problems and Styles20 ALTERNATIVE SET MODEL FULL PROFESSORS associate ASSOCIATE PROFESSORS ASSISTANT PROFESSORS assistantfull P#, PNAME, PADDRESS, PTEL P#

Section 1010 ER Problems and Styles21 SUPERTYPES and SUB TYPES A company operate cars, lorries and buses; furthermore these are the only type vehicles it operates. Suppose we are developing a data model for this company. One possible solution would be to use SET TYPE (92) and to have tables VEHICLE and VEHICLE TYPE to indicate CAR, LORRY or BUS. VEHICLE TYPE veh_type VEHICLEveh_typeVEHICLE_TYPE vno reg vno vtypenovtypeno vtype V1 Smith V1 BBBUS V2 Jones V2 BCCAR V3 Brown V3 C L LORRY V4 Green V4 L VEHICLE

Section 1010 ER Problems and Styles22 However each vehicle type in reality requires different attributes. ie A bus would require passenger capacity ie A bus would require passenger capacity A lorry would require tonnage and no’ of axles A lorry would require tonnage and no’ of axles Furthermore each of the vehicle types may require different relationship participation. ie BUS services a ROUTE ie BUS services a ROUTE EMPLOYEE keeps a CAR EMPLOYEE keeps a CAR EMPLOYEES can drive VEHICLES EMPLOYEES can drive VEHICLES A SOLUTION WOULD BE TO USE THE ALTERNATIVE SET MODEL (95) THE MODEL BELOW IS WITHOUT THE DIAMOND NOTATION IT MAKES USE OF SUPERTYPES & SUB TYPES

Section 1010 ER Problems and Styles23 VEHICLE CAR LORRY BUS EMPLOYEEROUTE keeps can drive is served by ER MODEL - VEHICLES REDRAW THE ABOVE ER DIAGRAM USING THE DIAMOND NOTATION. NOTE : THIS STYLE IS NOT MODELLED BY ASCENT

Section 1010 ER Problems and Styles24

Section 1010 ER Problems and Styles25 EXISTENCE DEPENDENCE EMPLOYEE emp - nok NEXT OF KIN E#, ENAME, EADDRESS, ETEL NOK#, NOKNAME, NOKADDRESS, NOKTEL E#, NOK# PRECEDENCE RELATIONSHIP ORDER DESPATCH order-despatch O#, OTOTAL, ODATE D#, DDATE O#, D#

Section 1010 ER Problems and Styles26 WEAK ENTITY TYPE (OPTIONAL entities shown in double box) EMPLOYEE DEPENDENT ID E#, ENAME, EADDRESS, ETEL D#, DNAME, DADDRESS, DTEL E#, D# NOTE : THIS STYLE IS NOT MODELLED BY ASCENT

Section 1010 ER Problems and Styles27 HIGH-LEVEL ENTITY TYPE HIGH-LEVEL ENTITY TYPE : Style 1 (relationship types defined on relationships) PRODUCTCUSTOMER shipping performed by AGENT SEE TERNARY RELATIONSHIP for improvements to above model. ‘Products are shipped to customer. Shipping is performed by a Shipping Agent.’ P#, Pname, Pdesc C#, Cname, Caddress, Ctel A#, Aname, Aaddress, Atel S#, Sdate A#, S# NOTE : THIS STYLE IS NOT MODELLED BY ASCENT

Section 1010 ER Problems and Styles28 HIGH-LEVEL ENTITY TYPE HIGH-LEVEL ENTITY TYPE : Style 2 (relationship types defined on relationships) PRODUCTCUSTOMER shipping performed by AGENT P#, Pname, PdescC#, Cname, Caddress, Ctel P#, C# S#, A# S#, Sdate A#, Aname, Aaddress, Atel SEE TERNARY RELATIONSHIP for improvements to above model. NOTE : THIS STYLE IS NOT MODELLED BY ASCENT

Section 1010 ER Problems and Styles29 TERNARY RELATIONSHIP TYPE (multi relationship types) PRODUCTCUSTOMER shipping AGENT P#, Pname, PdescC#, Cname, Caddress, Ctel A#, Aname, Aaddress, Atel P# C#, A#

Section 1010 ER Problems and Styles30 C#, Cname, Caddress, CtelP#, Pname, Pdesc A#, Aname, Aaddress, Atel S#, Sdate S#, P#, C#, A# NOTE : THIS STYLE IS NOT MODELLED BY ASCENT QUAD RELATIONSHIP TYPE

Section 1010 ER Problems and Styles31 RECURSIVE RELATIONSHIP TYPE (mapping onto one entity types) EMPLOYEE manages E#, ENAME, EADDRESS, ETEL managerE#, workerE# NOTE : THIS STYLE IS NOT MODELLED BY ASCENT SEE BINARY relationship to model this in ASCENT.. TEAM plays

Section 1010 ER Problems and Styles32 BINARY RELATIONSHIPS EMPLOYEE MANAGER supervise (Used to improve recursive relationships.) E#, ENAME, EADDRESS, ETEL manager worker E# E# manager E#

Section 1010 ER Problems and Styles33 BINARY RELATIONSHIPS using SUPER & SUB TYPES – Employee Example (Used to improve recursive relationships.) EMPLOYEE MANAGER WORKER contracts supervises REDRAW THE ABOVE ER DIAGRAM USING THE DIAMOND NOTATION. NOTE : THIS STYLE IS NOT MODELLED BY ASCENT

Section 1010 ER Problems and Styles34

Section 1010 ER Problems and Styles35 TWO OR MORE RELATIONSHIPS BETWEEN ENTITIES ITEM CUSTOMER returned by sold to I#, Iname, Idesc C#, Cname, Caddress, Ctel. I#, C#, Qty, date

Section 1010 ER Problems and Styles36 ERD SAMPLES Ascent Resources Ascent S/W and ERD Solutions Installing Ascent At Home Using Ascent - ER Modeling Library of Free Data Models

Section 1010 ER Problems and Styles37 End of Lecture

Similar presentations