Concepts of Database Management Seventh Edition Chapter 4 Keys and Relationship.

Slides:



Advertisements
Similar presentations
The Relational Model J.G. Zheng May 15 th Introduction Edgar F. Codd, 1970 One sentence to explain relational database model: Data are organized.
Advertisements

Database Creation and Management
Management Information Systems, Sixth Edition
Concepts of Database Management Seventh Edition Chapter 6 Database Design : ERD Model.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
Chapter 8 Embedded SQL.
ISP 121 Access Normalization and Relationships. Normalization Say we’re operating a pet day-care and we need to keep information on our pets/customers.
Concepts of Database Management Sixth Edition
Concepts of Database Management, 4th Edition, Pratt & Adamski
1 6 Concepts of Database Management, 4 th Edition, Pratt & Adamski Chapter 6 Database Design 2: Design Methodology.
3-1 Chapter 3 Data and Knowledge Management
SQL – Part II Yong Choi School of Business CSU, Bakersfield.
1 1 Concepts of Database Management, 4 th Edition, Pratt & Adamski Chapter 1 Introduction to Database Management.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Concepts of Database Management Sixth Edition
Concepts of Database Management Seventh Edition Chapter 1 Introduction to Database Management.
Concepts of Database Management Seventh Edition
SQL (Standard Query Language) Yong Choi School of Business CSU, Bakersfield.
Part ( PartNum, Description, OnHand, Class, Warehouse, Price,
MS Access 2007 IT User Services - University of Delaware.
ACCESS CHAPTER 1. OBJECTIVES Tables Queries Forms Reports Primary and Foreign Keys Relationship.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Concepts of Database Management Seventh Edition
Concepts of Database Management Seventh Edition Chapter 5 Database Design 1: Normalization.
Mapping from Data Model (ERD) to Relational Model Yong Choi School of Business CSUB.
DAY 15: ACCESS CHAPTER 2 Larry Reaves October 7,
A Guide to SQL, Eighth Edition Chapter Two Database Design Fundamentals.
Chapter 1 Overview of Database Concepts Oracle 10g: SQL
Concepts of Database Management, Fifth Edition Chapter 4: The Relational Model 3: Advanced Topics.
Chapter 4 The Relational Model 3: Advanced Topics Concepts of Database Management Seventh Edition.
SQL – Part II Yong Choi School of Business CSU, Bakersfield.
1 Chapter 1 Overview of Database Concepts. 2 Chapter Objectives Identify the purpose of a database management system (DBMS) Distinguish a field from a.
Databases. Database A database is an organized collection of related data.
Data Modelling – ERD Entity Relationship Diagram’s Entity Relationship Diagrams and how to create them. 1.
Principles of Database Design, Part II AIMS 2710 R. Nakatsu.
Concepts of Database Management, Fifth Edition Chapter 1: Introduction to Database Management.
Mapping from Data Model (ERD) to Relational Model
Lecture 2 An Overview of Relational Database IST 318 – DB Admin.
RELATIONSHIPS Generally there are two main database types: flat-file and relational.
1 A Guide to MySQL 2 Database Design Fundamentals.
SQL 101 for Web Developers 14 November What is a database and why have one? Tables, relationships, normalization SQL – What SQL is and isn’t – CRUD:
McGraw-Hill/Irwin © 2008 The McGraw-Hill Companies, All Rights Reserved Plug-In T5: Designing Database Applications Business Driven Technology.
1 n 1 n 1 1 n n Schema for part of a business application relational database.
Organizing Data Revision: pages 8-10, 31 Chapter 3.
1 A Guide to MySQL 2 Database Design Fundamentals.
M1G Introduction to Database Development 2. Creating a Database.
Chapter 1Introduction to Oracle9i: SQL1 Chapter 1 Overview of Database Concepts.
1 CSE 2337 Introduction to Data Management Textbook: Chapter 1.
Introduction to Database using Microsoft Access 2013 Part 7 November 19, 2014.
The Relational Model J.G. Zheng Jan 2010 CIS 8040 Database Management Systems.
INFORMATION TECHNOLOGY DATABASE MANAGEMENT. Adding a new field 1Right click the table name and select design view 2Type the field information at the end.
Concepts of Database Management, Fifth Edition Chapter 6: Database Design 2: Design Methodology.
Concepts of Database Management Seventh Edition Chapter 1 Introduction to Database Management.
Concepts of Database Management Seventh Edition Chapter 5 Database Design 1: Normalization.
Concepts of Database Management Seventh Edition Chapter 5 Database Design 1: Normalization.
BSA206 Database Management Systems Lecture 2: Introduction to Oracle / Overview of Database Concepts.
Concepts of Database Management Seventh Edition Chapter 6 Database Design 2: Design Method.
Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin APPENDIX C DESIGNING DATABASES APPENDIX C DESIGNING DATABASES.
1 6 Concepts of Database Management, 5 th Edition, Pratt & Adamski Chapter 6 Database Design 2: Design Methodology Spring 2006.
Concepts of Database Management, Fifth Edition Chapter 6: Database Design 2: Design Methodology.
Howard Paul. Sequential Access Index Files and Data File Random Access.
Concepts of Database Management Seventh Edition Chapter 4 Keys and Relationship.
Southern Methodist University CSE CSE 2337 Introduction to Data Management Chapter 5 Part II.
Southern Methodist University CSE CSE 2337 Introduction to Data Management Chapter 2.
Copyright © it’sLearning 365. All rights reserved. DATABASE CONCEPTS Understanding Databases Start …
XP Chapter 1 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Level 2 Objectives: Understanding and Creating Table.
A Guide to SQL, Eighth Edition
Database, tables and normal forms
Concepts of Database Management Seventh Edition
Chapter 14 Normalization Pearson Education © 2009.
Presentation transcript:

Concepts of Database Management Seventh Edition Chapter 4 Keys and Relationship

Objectives Understand different type of keys in a Table. Understand the different type of Table relationship Identify the primary key and foreign key to create a relationship. Create primary and foreign key in an actual DBMS 2

Table Relationship Remember in Chapter 1 we discuss the hierarchy of data, namely: –Field or Column –Record or Row –Table or File –Database Now, Tables normally does not stand alone, that is, in the modern database software like MS Access, mySQL, Oracle or MS SQL, table(s) normally has relationship with another table. 3

Three Types of Relationship There are three types of table relationship: –One to one or denoted as 1:1 –One to many or denoted as 1:M –Many to Many or denoted as M:N 4

Examples of One-to-One Relationship A student belongs to only one Program A student has one and only ID An employee has one computer assign Could you name your own example? 5

Examples of One-to-Many Relationship A Division could have more than one Program offered A Program could have many students enrolled Could you name your own example? 6

Examples of Many-to-Many Relationship A student could take many course and a course could have many students An author could have many books and a book could have many author A music album could have many artists/performers and an artist/performer could have many albums Could you name your own example? 7

Key in a table A key in a table is a field or group of fields that creates identity, makes relationship with another table and/or make a table more efficient. 8

Primary Key & Foreign A Primary key is a key that uniquely identifies a row in each table. It is normally denoted with its first two letters, namely, PK. A Foreign key is a key borrowed from another related table (that’s why its foreign) in order to make the relationship between two tables. It is normally denoted with its first two letters, namely, FK. 9

Examples from Premier Database – Primary Key 10 Repnum uniquely identifies the Rep table and is the primary key of this table.

Examples from Premier Database – Primary Key 11 Customernum uniquely identifies the Customer table and is the primary key of this table.

Examples from Premier Database – Primary Key 12 Ordernum and Partnum makes up the primary key Of the OrderLine table. This is what is known as a Composite Primary key, that is, primary key that is made up of more than one field.

Examples from Premier Database Could you identify any more primary keys from Premier Database? 13

Examples from Premier Database – Foreign Key 14 Repnum is a Foreign key borrowed from Rep table

Examples from Premier Database Could you identify any more foreign keys from Premier Database? 15

Notation example One Rep could have one or more customer (one to many) using Primary and foreign key to create the relationship. 16 Customer Customernum (PK) Customername Street City State Zip Balance CreditLimit Repnum (FK) Rep Repnum (PK) Lastname Firstname Street City State Zip Commission Rate 1 M

Notation example Always remember the many side has the Foreign key. In this case the many side is on the Customer table and therefore has the foreign key Repnum which is the primary key of Rep table. 17 Customer Customernum (PK) Customername Street City State Zip Balance CreditLimit Repnum (FK) Rep Repnum (PK) Lastname Firstname Street City State Zip Commission Rate 1 M

Examples from Premier Database Could you identify the different relationship among tables in Premier Database because of the Primary and Foreign keys? 18

Referential Integrity Referential Integrity means that the Foreign key must match in terms of actual values and data types with the related Primary Key. 19

Referential Integrity Example: The foreign key RepNum in Customer must match with the primary key RepNum in Rep table. 20

Referential Integrity In terms of Data Type Customer RepNum (Foreign Key) has Text Data type and Rep RepNum (Primary Key) has also Text Data type. 21

Seatwork 22 Alexamara and Henry Books Identify the primary key and foreign keys for each table. Put the name of the table and name its primary key and if there is a foreign key identify the foreign key. Identify how each table that has the foreign key relates to another table. See slide No. 16 and 17

Demo in creating Primary and Foreign Key in MS Access 23

Referential Integrity In terms of actual Values 24

Non-Graded Seatwork 25 Alexamara and Henry Books –Check the tables that are related to each other and then check data types for both Foreign and Primary Keys that are related. –Check also the values of the related Primary Keys if you could find it in the related Foreign keys. –Try to enter values in the Foreign Key that could not be found in related table that has the Primary Key. Did MS Access pops out an error message? What does it say?

On-your-own Exercise 26 –Imagine we want to make a simple appointment database for a small clinic here in Pohnpei with a fictitious name Health Wealth clinic. And the database would record appointments for Patients with their Doctor on a given date. –Now a Patient could have one or more appointments in Health Wealth clinic to one or more Doctor. –A Doctor could also have one or more appointment with one or more patients every day. –Create three tables, namely, Patients, Doctors and Appointments. –Create necessary fields for each table that you think should be there. –Create a Primary Key for each tables. –And create also Foreign keys if necessary to create relationship among tables. –Use the Database Tools to create the Relationship among tables after you created both the Primary Keys and Foreign Keys. –Show your work to me after you are done.

Summary (continued) Modern database normally has tables that has logical relationships with one another. Three primary type of relationships are one-to-one, one-to-many and many-to-many. Each row/record in a Table should be unique using a Primary Key To create a relationship among tables you must have the Foreign key on the other table. Referential Integrity protects the integrity of your data by matching both your Primary key and Foreign in terms of Data types and actual values. 27