Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Design GET/INT – Computer Science Dept. 2 Database Design Contents Introductionslide 3 Entity-Relationship modelslide 8 E/R  relational mappingslide.

Similar presentations


Presentation on theme: "Database Design GET/INT – Computer Science Dept. 2 Database Design Contents Introductionslide 3 Entity-Relationship modelslide 8 E/R  relational mappingslide."— Presentation transcript:

1 Database Design GET/INT – Computer Science Dept

2 2 Database Design Contents Introductionslide 3 Entity-Relationship modelslide 8 E/R  relational mappingslide 13 Reverse engineering slide 25

3 3 Database Design Data model-independent Database design Reality Conceptual Schema Relational Schema Codasyl Schema Files…. Mapping Introduction

4 4 Database Design Relational-based database design Universal relation Functional dependencies Decomposition Normalized relational schema Introduction

5 5 Database Design Centralized database design Global conceptual Schema Local Schema Local Schema …. Local Schema ProgramUser… Introduction

6 6 Database Design Decentralized database design (from existing schema ) Integration Global schema Local schema Heterogeneous/homogeneous Introduction

7 7 Database Design Database design Introduction MiniWorld Requirements collection and analysis Database requirements Conceptual design Conceptual schema (high level) Data model mapping Conceptual schema (of a specific DBMS) Physical design Internal schema (for the same DBMS) DBMS-independent DBMS-dependent

8 8 Database Design Entity-Relationship Model defined in 1976 (Chen) Numerous extensions since 1976 Advantages: Used in numerous design methods (MCD Merise, UML Class diagram …) Simple Graphical Ease discussion with users E/R model

9 9 Database Design Concepts E/R Model Graphism 1 (E/R)Graphism 2 (AMCDesignor) Entity type Attribute Composite Attribute Multivalued Attribute Key attributes Relationship type Role Cardinality ratio Name Type Entity T A A Ass Role 0,n1,n

10 10 Database Design Concepts (2) E/R Model Graphism 1Graphism 2 Weak entity type Identifying relationship Derived attribute Ass (1,1)

11 11 Database Design Company E/R model E/R Model Employee nameaddressSSN fnamelname DependentProject Department hours Dept_numberdeptname numberDescriptionname locations Dependents_of Manages Works_for Works_on controls startdate 0,n1,n 0,1 0,n 1,1 1,n 1,1 0,n Emp_nb supervision supervisor 0,n supervisee 1,1 birthdate relationship

12 12 Database Design Company E/R model Graphism 2 E/R Model 1,n 1,1 supervisee 0,n supervisor (1,1) 0,n 1,1 1,n 1,1 0,1 1,n 1,1 Employee Nssn Address fname lname Department Dept_number Dept_name Emp_nb Project number Description Dependent name birthdate relationship Works_for manages startdate controls Dependents_of Supervision Works_on hours locations

13 13 Database Design Mapping E/R  relational Semantic is not completely preserved (we have to add integrity constraints) Rules can be automated (numerous commercial tools exist, AMCDesignor for example) Mapping is done in 7 steps Comparison of E/R concepts and relational concepts: To do Mapping

14 14 Database Design Step 1 : mapping non weak entity types Entity type  relation Atomic Attribute  attribute Composite Attributes  n attributes Key(s) Attribute(s)  logical key mapping EKAEKA E(K, A)

15 15 Database Design Examples step 1 mapping EmployeeAtomic AttributesEmployee(ssn, address) Composite attributesEmployee(ssn, address, fname, lname) Composite attributes are flatten  loss of semantic DepartmentAtomic AttributesDepartment(no_dept, libelle) Multivalued attributesstep 6 : location Derived Attributesstep 7 : emp_nb ProjectAtomic AttributesProject(number, description)

16 16 Database Design Step 2 : mapping of weak entities Weak entity type  relation Atomic Attribute  attribute Composite Attributes  n attributes Key(s) Attribute(s)  part of logical key Key Attributes from identifying entity  part of logical key mapping EKAEKA E2 K2 A2 (1,1) E2(K, K2, A2)

17 17 Database Design Example step 2 mapping Entity dependentAtomic AttributesDependent(name, birthdate, relationship) + Identifying entity key Dependent(name, ssn, birthdate, relationship) ssn: Foreign key on Employee + Part of Dependent key

18 18 Database Design Step 3 : mapping of mono-valued binary relationships Key associated to E1  attribute of E2 Attributes of relationship RS  attributes of E2 mapping E1 K1 A1 E2 K2 A2 ?,1 E2(K2, A2, K1, A3) ?,? RS A3 Foreign key, but not key of E2

19 19 Database Design Examples step 3 mapping Works_forEmploye(ssn, address, fname, lname, deptnb) ManagesDepartment(dept_nb, dept_name, ssnmgr, startdate) Manages mono-valued in both directions  other possible mapping Employee(ssn, address, fname, lname, deptnb, manageddeptnb, startdate) Cardinality (0,1), partial relationship  null values ControlsProject(number, description, deptnum) SupervisionEmployee(ssn, address, fname, lname, deptnb, ssnsupervisor) ssnsuperrvisor foreign key of Employé on Employee Dependents_ofSee step 2

20 20 Database Design Step 4 : mapping multivalued binary relationships (on both directions) Creation of a new relation RS E1 key + E2 key  RS key Attributes of RS  Attributes of RS mapping E1 K1 A1 E2 K2 A2 ?,n RS(K1, K2, A3) ?,n RS A3 Works_onWorks_on(ssn, projectnumber, hours)

21 21 Database Design Step 5 : mapping of n-ary relationships (n > 2) like step 4 : Creation of a new relation RS E1 key + E2 key + … En key  RS key RS Attributes  RS Attributes mapping E1 K1 A1 E2 K2 A2 RS(K1, K2, K3, A4) RS A4 E3 K3 A3

22 22 Database Design Step 6 : mapping of multivalued attributes Creation of a new relation R Multivalued Attribute -> attribute Key of Associated entity type -> attribute key of the new relation: the whole schema mapping R A C R(A, C) Locations in DepartmentLocation (location, dept_nb)

23 23 Database Design Step 7 : mapping of derived attributes Derived attribute Associated query mapping Emp_nb in Department Department(dept_nb, dept_name, ssnmgr, startdate) SELECT dept_nb, COUNT(*) FROM Employee GROUP BY dept_nb Query may be associated to a relational view

24 24 Database Design Example summary Employee(ssn, address, fname, lname, deptnb, ssnsupervisor) Department(dept_nb, dept_name, ssnmgr, startdate, emp_nb) Project(number, description, deptnb) Dependent(name, ssn, birthdate, relationship) Works_on(ssn, projectnumber, hours) Location(location, dept_nb) SELECT deptnb, COUNT(*) FROM Employee GROUP BY deptnb mapping

25 25 Database Design Reverse engineering Goal: Map a relational schema to a entity-relationship schema Why ? Database design has not been done or is lost how ? Apply mapping steps « in reverse order » Remark There is not a unique solution (loss of information on the relational schema compared to E/R schema) Reverse engineering

26 26 Database Design Reverse engineering principles Relation without a foreign key : entity type Relation with a foreign key outside its key : entity type and monovalued relationship to the entity type corresponding to the foreign key Reverse of Step 1 Step 3

27 27 Database Design Reverse engineering (2) Relation with a key exclusively composed by foreign keys : multivalued relationship among entity types corresponding to foreign keys Relation with a key composed by a foreign key and a local key : weak entity type identifyed by entity type corresponding to the foreign key Reverse of Step 4 and 5 Step 2


Download ppt "Database Design GET/INT – Computer Science Dept. 2 Database Design Contents Introductionslide 3 Entity-Relationship modelslide 8 E/R  relational mappingslide."

Similar presentations


Ads by Google