Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Design Chapter 9 Part-1: Concepts & Foreign Keys 1.

Similar presentations


Presentation on theme: "Database Design Chapter 9 Part-1: Concepts & Foreign Keys 1."— Presentation transcript:

1 Database Design Chapter 9 Part-1: Concepts & Foreign Keys 1

2  Part One Data Management Dept Types of DBs From Conceptual Data Model to a Database Relational DB Model Designing a Relational DB − Multi-valued Attributes − Representing Relationships − Referential Integrity Outline 2

3 Different Focus Requirements  Use Cases – the user must be able to: Enter orders Track order status Enter/assign/resolve complaints  Data Model – the system must be able to capture: Order # Order Date Customer Info Billing address Shipping address Products, & quantity Price, discounts Data Administrator Systems Analyst Primary responsibility Assist to ensure consistency w/existing systems

4 Data Management Dept. Database Data Administrator Database Administrator (DBA) Data Standards - Naming, etc Data use - Ownership, accessibility Data quality - Integrity rules Managing the DBMS environment Performance monitoring & tuning Security Backup & Recovery

5  Types of Databases Hierarchical Network Relational Object-oriented  Relational Database Management System (RDBMS) organizes data into tables (i.e. relations) − Tables are two dimensional data structures Record – row or tuple Field – column or attribute 5 Types of Databases

6 From Conceptual Data Model to a Database 6 Conceptual Data ModelDatabase ERD Domain Class DiagramRDBMS EntityClassTable Attribute Field InstanceObjectRecord Primary KeyIdentifierPrimary Key RelationshipAssociationForeign Key

7  (def) a model where data is represented as a set of related tables or relations. Properties/Rules of Relations: − Entries in cells are simple. (Rule of Atomic Values) − Entries in columns are from the same set of values. (Domain) − Each row is unique. (Primary Key) − Order of columns may be interchanged − Order of rows may be interchanged − Other Rules come from “Normalization” 7 Relational Database Model

8 TopicDescription Tables Create TBs – 1 for each entity/domain class Primary Keys Select/define a PK for each TB Associative Create new tables to represent many-to-many relationships Multi-Valued Attributes Resolve to new tables Foreign Keys Add FKs to establish relationships Super & Sub Classes Decide on how to represent any Generalization Hierarchies Referential Integrity Define Referential Integrity constraints Normalization Evaluate schema quality and make necessary improvements Data Types Determine appropriate data types for validation, integrity 8 Designing a Relational DB

9  No Multi-Valued Attributes  Due to the Rule of Atomic Values 9 Multi-Valued Attributes Employee Table SSNLastNameFirstNameTitleDependents 111SmithRobertAccountantBobbie, Sue 222JonesLeoProgrammer 333LopezTrentSales RepTrent Jr, Trevor, Sue Dependents Table SSNDependents 111Bobbie 111Sue 333Trent Jr 333Trevor 333Sue PK? Employee SSN {key} lastName firstName title dependents SSN {key} lastName firstName title dependents Employee Table SSNLastNameFirstNameTitle 111SmithRobertAccountant 222JonesLeoProgrammer 333LopezTrentSales Rep

10  One to Many Relationship create foreign key in the relation that is on the “many” side of relationship only − NOTE: Going the other way would generate a multi-value attribute 10 Foreign Keys: Establishing Relationships employs PKFK Add DeptCd here Copy it over Department deptCd {key} deptName location deptCd {key} deptName location Employee SSN {key} lastName firstName title SSN {key} lastName firstName title 1 *

11  One to One Relationship create foreign key in either relation − NOTE: IF you have one & only one on both sides, these may be merged into a single table 11 Foreign Keys: Establishing Relationships is assigned PKFK Copy it over Add SSN here ParkingSpace psNo {key} level Accessible? psNo {key} level Accessible? Employee SSN {key} lastName firstName title SSN {key} lastName firstName title PKFK Copy it over Add psNo here 1 1

12 PKFK Copy it over  Many to Many Relationship should’ve been eliminated on ERD!!! create new relation with PKs of related entities as: − 1 concatenated PK, and 2 FKs 12 Foreign Keys: Establishing Relationships PKFK Copy it over (PK) Employee SSN {key} lastName firstName title SSN {key} lastName firstName title Project projCd {key} projName desc stDate endDate projCd {key} projName desc stDate endDate EmpProject __________ role stDate __________ role stDate 0..* 1..11..*1..1 EmpProject Employee Project 0..*1..*

13 Super & Sub Classes  2 Options to Implement Separate Tables − Student (SID, name, birthDate) − UndergradStudent (SID, mentor) − GradStudent (SID, thesisTopic) One Table − Student (SID, name, birthDate, mentor, thesisTopic, studentType) 13 Student Undergrad Student Grad Student SID {key} name birthDate mentorthesisTopic

14 Referential Integrity  Referential Integrity (def) an integrity constraint on the Foreign Key: 1.Prevents adding a FK value, if an associated PK value does not exist. 2.Prevents delete of PK value, if an associated FK value exists. 3.Prevents change of PK value, if an associated FK value exists. Can override: − Cascade Delete  Overrides constraint #2 − Cascade Update  Overrides constraint #3 14


Download ppt "Database Design Chapter 9 Part-1: Concepts & Foreign Keys 1."

Similar presentations


Ads by Google