comp4 unit6b lecture slides

14
Introduction to Information and Computer Science Databases and SQL Lecture b This material (Comp4_Unit6b) was developed by Oregon Health & Science University, funded by the Department of Health and Human Services, Office of the National Coordinator for Health Information Technology under Award Number IU24OC000015.

Upload: health-it-workforce-curriculum-2012

Post on 06-May-2017

258 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Comp4 Unit6b Lecture Slides

Introduction to Information and Computer ScienceDatabases and SQL

Lecture b

This material (Comp4_Unit6b) was developed by Oregon Health & Science University, funded by the Department of Health and Human Services, Office of the National Coordinator for Health Information Technology under Award Number

IU24OC000015.

Page 2: Comp4 Unit6b Lecture Slides

Databases and SQLLearning Objectives

2

• Define and describe the purpose of databases (Lecture a)• Define a relational database (Lecture a)• Describe data modeling and normalization (Lecture b)• Describe the structured query language (SQL) (Lecture c)• Define the basic data operations for relational databases and how to

implement them in SQL (Lecture c)• Design a simple relational database and create corresponding SQL

commands (Lecture c)• Examine the structure of a healthcare database component (Lecture

d)

Health IT Workforce Curriculum Version 3.0/Spring 2012

Introduction to Information and Computer Science Databases and SQL

Lecture b

Page 3: Comp4 Unit6b Lecture Slides

Representing Data• Identify entities (tables)• Identify attributes (columns)• Identify table relationships

6.8 Figure: Entity-Relationship Diagram (ER diagram) (PD-US, 2012)

3Health IT Workforce Curriculum Version 3.0/Spring 2012

Introduction to Information and Computer Science Databases and SQL

Lecture b

Page 4: Comp4 Unit6b Lecture Slides

Relationships• One-to-one• One-to-many• Many-to-many

4Health IT Workforce Curriculum Version 3.0/Spring 2012

Introduction to Information and Computer Science Databases and SQL

Lecture b

6.9 Figure: One-to-many relationship (PD-US, 2012)

Page 5: Comp4 Unit6b Lecture Slides

Identify the Data

• A contact:– Person’s first name– Person’s last name– Company name– Company address– Company city– Company state

5Health IT Workforce Curriculum Version 3.0/Spring 2012

Introduction to Information and Computer Science Databases and SQL

Lecture b

Page 6: Comp4 Unit6b Lecture Slides

Simple Database Structure• One entity/table• Create a unique row identifier• Attributes:

– Key (integer)– Person’s first name (varchar)– Person’s last name (varchar)– Company name (varchar)– Company address (varchar)– Company city (varchar)– Company state (char)

6.10 Table: Contact attributes (PD-US, 2012)

6Health IT Workforce Curriculum Version 3.0/Spring 2012

Introduction to Information and Computer Science Databases and SQL

Lecture b

ContactKeyPersonFirstNamePersonLastNameCoNameCoAddressCoCityCoState

Page 7: Comp4 Unit6b Lecture Slides

Contact TableKey PersonFirst

NamePersonLastName

CoName CoAddress CoCity CoState

1 Bill Robeson Community Hospital, Inc.

1312 Main Portland OR

2 Albert Brookings Community Hospital Inc.

1312 Main St. Portland OR

6.11 Table: Contact table (PD-US, 2012)

Problems:– Company data is stored in multiple locations– Company data may be inconsistent– Significant work to update data when company

information changes

7Health IT Workforce Curriculum Version 3.0/Spring 2012

Introduction to Information and Computer Science Databases and SQL

Lecture b

Page 8: Comp4 Unit6b Lecture Slides

Database Normalization

• Prevent data inconsistency• Prevent update errors• Eliminate data redundancy

8Health IT Workforce Curriculum Version 3.0/Spring 2012

Introduction to Information and Computer Science Databases and SQL

Lecture b

Page 9: Comp4 Unit6b Lecture Slides

Normalized Database StructureTwo tables: Person and CompanyEach has a unique row identifier – a primary keyNeed to link the company to the contact

6.12 Figure: Normalized database structure (PD-US, 2012)

9Health IT Workforce Curriculum Version 3.0/Spring 2012

Introduction to Information and Computer Science Databases and SQL

Lecture b

Page 10: Comp4 Unit6b Lecture Slides

New Tables

Person Table

ContactKey FirstName LastName CompanyKey

1 Bill Robeson 1

2 Albert Brookings 1

6.13 Tables: New tables using same data from Table 6.5 (PD-US, 2012)

10Health IT Workforce Curriculum Version 3.0/Spring 2012

Introduction to Information and Computer Science Databases and SQL

Lecture b

Company Table

CompanyKey

Name Address City State

1 Community Hospital, Inc.

1312 Main Portland OR

Page 11: Comp4 Unit6b Lecture Slides

How Do We Do This?• Database Management System

– Create– Maintain– Use

• Many available (NOT an exhaustive list)– Oracle– Microsoft SQL Server– IBM DB2– MySQL– PostgreSQL

11Health IT Workforce Curriculum Version 3.0/Spring 2012

Introduction to Information and Computer Science Databases and SQL

Lecture b

Page 12: Comp4 Unit6b Lecture Slides

Building a Database

• Database Management System Tools– Create tables– Create relationships– Control access– More…

• Structured Query Language (SQL)– Database management– Access to data

12Health IT Workforce Curriculum Version 3.0/Spring 2012

Introduction to Information and Computer Science Databases and SQL

Lecture b

Page 13: Comp4 Unit6b Lecture Slides

Databases and SQLSummary – Lecture b

• Databases can be modeled using entity relationship diagrams

• Relationships can have 3 different types of cardinality

• Normalization avoids duplicate data• Relationships are created using foreign keys

13Health IT Workforce Curriculum Version 3.0/Spring 2012

Introduction to Information and Computer Science Databases and SQL

Lecture b

Page 14: Comp4 Unit6b Lecture Slides

Databases and SQLReferences – Lecture b

References• Chen, P. P.-S. (1976). The Entity-Relationship Model - Toward a Unified View of Data. ACM Transactions on

Database Systems, 1(1).• International Organization for Standardization. (2008). Information technology -- Database languages -- SQL (No.

ISO/IEC 9075-(1-4,9-11,13,14)).• Kent, W. (1983). A simple guide to five normal forms in relational database theory. Communications of the ACM,

26(2).

14Health IT Workforce Curriculum Version 3.0/Spring 2012

Introduction to Information and Computer Science Databases and SQL

Lecture b

Charts, Tables, Figures• 6.8 Figure: Entity-Relationship Diagram (ER diagram) (PD-US, 2012)• 6.9 Figure: One-to-many relationship (PD-US, 2012)• 6.10 Table: Contact attributes (PD-US, 2012)• 6.11 Table: Contact table (PD-US, 2012)• 6.12 Figure: Normalized database structure (PD-US, 2012)• 6.13 Tables: New tables using same data from Table 6.5 (PD-US, 2012)