Вы находитесь на странице: 1из 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.
Databases and SQL
Learning 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
Representing Data
Identify entities (tables)
Identify attributes (columns)
Identify table relationships

6.8 Figure: Entity-Relationship Diagram (ER diagram) (PD-US, 2012)
3
Health IT Workforce Curriculum
Version 3.0/Spring 2012
Introduction to Information and Computer Science
Databases and SQL
Lecture b
Relationships
One-to-one
One-to-many
Many-to-many

4
Health 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)
Identify the Data
A contact:
Persons first name
Persons last name
Company name
Company address
Company city
Company state
5
Health IT Workforce Curriculum
Version 3.0/Spring 2012
Introduction to Information and Computer Science
Databases and SQL
Lecture b
Simple Database Structure
One entity/table
Create a unique row identifier
Attributes:
Key (integer)
Persons first name (varchar)
Persons last name (varchar)
Company name (varchar)
Company address (varchar)
Company city (varchar)
Company state (char)
6.10 Table: Contact attributes (PD-US, 2012)


6
Health IT Workforce Curriculum
Version 3.0/Spring 2012
Introduction to Information and Computer Science
Databases and SQL
Lecture b
Contact
Key
PersonFirstName
PersonLastName
CoName
CoAddress
CoCity
CoState
Contact Table
Key
PersonFirst
Name
PersonLast
Name
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

7
Health IT Workforce Curriculum
Version 3.0/Spring 2012
Introduction to Information and Computer Science
Databases and SQL
Lecture b
Database Normalization
Prevent data inconsistency
Prevent update errors
Eliminate data redundancy
8
Health IT Workforce Curriculum
Version 3.0/Spring 2012
Introduction to Information and Computer Science
Databases and SQL
Lecture b
Normalized Database Structure
Two tables: Person and Company
Each has a unique row identifier a primary key
Need to link the company to the contact





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



9
Health IT Workforce Curriculum
Version 3.0/Spring 2012
Introduction to Information and Computer Science
Databases and SQL
Lecture b
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)


10
Health IT Workforce Curriculum
Version 3.0/Spring 2012
Introduction to Information and Computer Science
Databases and SQL
Lecture b
Company Table
Company
Key
Name Address City State
1 Community
Hospital, Inc.
1312 Main Portland OR
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

11
Health IT Workforce Curriculum
Version 3.0/Spring 2012
Introduction to Information and Computer Science
Databases and SQL
Lecture b
Building a Database
Database Management System Tools
Create tables
Create relationships
Control access
More
Structured Query Language (SQL)
Database management
Access to data

12
Health IT Workforce Curriculum
Version 3.0/Spring 2012
Introduction to Information and Computer Science
Databases and SQL
Lecture b
Databases and SQL
Summary 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
13
Health IT Workforce Curriculum
Version 3.0/Spring 2012
Introduction to Information and Computer Science
Databases and SQL
Lecture b
Databases and SQL
References 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).
14
Health 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)

Вам также может понравиться