Presentation is loading. Please wait.

Presentation is loading. Please wait.

DATA MODELING AND DATABASE DESIGN DATA MODELING AND DATABASE DESIGN Part 2.

Similar presentations


Presentation on theme: "DATA MODELING AND DATABASE DESIGN DATA MODELING AND DATABASE DESIGN Part 2."— Presentation transcript:

1 DATA MODELING AND DATABASE DESIGN DATA MODELING AND DATABASE DESIGN Part 2

2 Objectives Resolving ERD with LINK entities Recursive relationships Levels of normalization Integrity constraints Candidate keys, primary and foreign keys

3 Resolving Many to Many Relationships Most many to many relationships must be resolved before they can be mapped to a database design. We resolve that by creating new entity called LINK or INTERSECTION ENTITY. CREATE an INTERSECTION ENTITY to control this relationship EMPLOYEE_ NEW_FORCE ACTIVITY performs an requires an

4 RESOLVED ERD EMPLOYEE_ NEW_FORCE ACTIVITY EMPLOYEE -ACTIVITY * per_diem_rate # emp_no * position o job_description * salary o commission # activity_id * description o start_date o end_date * internal requires an for performs an performed by

5 Recursive Relationships Define a relationship between an entity and itself as a recursive relationship. Represent that relationship with a “pig’s ear.” EMPLOYEE #* id *last name ofirst name * salary *start date o manager_id managed by managed by the manager of the manager of

6 Level First normal form Second normal form Third normal form Characteristics All attributes must be single-valued. An attribute must depend upon its entity's entire UID (not only on part of UID) No non-UID attribute may be dependent upon another non-UID attribute. Levels of Normalization Benefits Minimizes data redundancy Reduces integrity problems Identifies missing entities and relationships

7 Unnormalized Form # emp_no * position * salary o commission o activity1 o act1_start_date o act1_end_date o activity2 o act2_start_date o act2_end_date o activity3 o act3_start_date o act3_end_date EMPLOYEE

8 First Normal Form EMPLOYEE # emp_no * position * salary o commission ACTIVITY # activity_id * description o start_date o end_date

9 Convert to third Normal Form EMPLOYEE # id * last name * department location DEPARTMENT # id * name has employed in

10 Third Normal Form EMPLOYEE # id * last name DEPARTMENT # id * name * location has employed in

11 Integrity Constraints Ensure data consistency Should be enforced by the database server or the application software Correspond to keys –Primary key, unique key and foreign key TypeEntityReferentialColumnUser-DefinedCharacteristics No part of a primary key can be NULL, and the value must be unique. Foreign key values must match a primary key or be NULL. Values in the column must match the defined datatype. Values must comply with business rules.

12 Defining a Primary Key A primary key (PK) allows no duplicate values and cannot be NULL. Each row is uniquely identified by a column or set of columns (composite primary key). There may be only one PK, but there may be many candidate keys. Emp_no activity_id per_diem_rate --------------------------------------------- 121011500 121011500 151011400 151011400 16910300 16910300 07421150 07421150 Composite Primary Key Table EMPLOYEE_ACTIVITY

13 Defining a Foreign Key A foreign key (FK) is a column in one table that refers to a PK in the same table or in another table. The value must either match the PK value in the ‘parent table’ or be NULL. If FK is part of a PK, then it cannot be NULL.

14 Defining a Foreign Key: Example The DEPT_ID column is an FK in the EMP table, and refers to values in the ID column of the DEPT table. IDLAST_NAMEFIRST_NAME...DEPT_ID... 1MartinezAna10 2KimToni31 3TakeshiTofiro21 4McCoyJames10 5GauletChantal20 IDNAMEREGION_ID 10Corporate1 20HR1 21Sales1 31Stock1 Primary Key Foreign Key EMP Table DEPT Table Primary Key


Download ppt "DATA MODELING AND DATABASE DESIGN DATA MODELING AND DATABASE DESIGN Part 2."

Similar presentations


Ads by Google