Download presentation
Presentation is loading. Please wait.
1
Chapter 9 Part-1: Concepts & Foreign Keys
Database Design Chapter 9 Part-1: Concepts & Foreign Keys
2
Outline 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
3
Different Focus Systems Analyst Data Administrator 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 Systems Analyst Data Administrator Primary responsibility Assist to ensure consistency w/existing systems
4
Database Administrator (DBA)
Data Management Dept. 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 Database
5
Types of Databases 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
6
From Conceptual Data Model to a Database
ERD Domain Class Diagram RDBMS Entity Class Table Attribute Field Instance Object Record Primary Key Identifier Relationship Association Foreign Key Cardinality Multiplicity ** ** Relationship rules –will learn in the DB class
7
Relational Database Model
(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”
8
Designing a Relational DB
Topic Description 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
9
Multi-Valued Attributes
No Multi-Valued Attributes Due to the Rule of Atomic Values Employee EmpID {key} lastName firstName title dependents Employee Table EmpID LastName FirstName Title Dependents 111 Smith Robert Accountant Bobbie, Sue 222 Jones Leo Programmer 333 Lopez Trent Sales Rep Trent Jr, Trevor, Sue Dependents Table EmpID Dependents 111 Bobbie Sue 333 Trent Jr Trevor PK? Employee Table EmpID LastName FirstName Title 111 Smith Robert Accountant 222 Jones Leo Programmer 333 Lopez Trent Sales Rep
10
Foreign Keys: Establishing Relationships
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 PK FK Add DeptCd here Copy it over Department deptCd {key} deptName location Employee EmpID {key} lastName firstName title 1 employs *
11
Foreign Keys: Establishing Relationships
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 PK FK Copy it over Add SSN here Employee EmpID {key} lastName firstName title ParkingSpace psNo {key} level Accessible? 1 is assigned 1 PK FK Copy it over Add psNo here
12
Foreign Keys: Establishing Relationships
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 Employee Project 1..* 0..* EmpProject PK FK Copy it over PK FK Copy it over Employee EmpID {key} lastName firstName title Project projCd {key} projName desc stDate endDate EmpProject __________ role stDate 1..1 0..* 1..* 1..1 (PK)
13
Super & Sub Classes 2 Options to Implement Separate Tables One Table
Student (SID, name, birthDate) UndergradStudent (SID, mentor) GradStudent (SID, thesisTopic) One Table Student (SID, name, birthDate, mentor, thesisTopic, studentType) Student Undergrad Student Grad Student SID {key} name birthDate mentor thesisTopic
14
Referential Integrity
(def) an integrity constraint on the Foreign Key: Prevents adding a FK value, if an associated PK value does not exist. Prevents delete of PK value, if an associated FK value exists. Prevents change of PK value, if an associated FK value exists. Can override: Cascade Delete Overrides constraint #2 Cascade Update Overrides constraint #3
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.