* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download comp4_unit6b_lecture_slides
Survey
Document related concepts
Microsoft Access wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Oracle Database wikipedia , lookup
Concurrency control wikipedia , lookup
Entity–attribute–value model wikipedia , lookup
Ingres (database) wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Microsoft SQL Server wikipedia , lookup
Clusterpoint wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Healthcare Cost and Utilization Project wikipedia , lookup
Transcript
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 • • • • • 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 2 Representing Data • Identify entities (tables) • Identify attributes (columns) • Identify table relationships 6.8 Figure: Entity-Relationship Diagram (ER diagram) (PD-US, 2012) Health IT Workforce Curriculum Version 3.0/Spring 2012 Introduction to Information and Computer Science Databases and SQL Lecture b 3 Relationships • One-to-one • One-to-many • Many-to-many 6.9 Figure: One-to-many relationship (PD-US, 2012) Health IT Workforce Curriculum Version 3.0/Spring 2012 Introduction to Information and Computer Science Databases and SQL Lecture b 4 Identify the Data • A contact: – Person’s first name – Person’s last name – Company name – Company address – Company city – Company state Health IT Workforce Curriculum Version 3.0/Spring 2012 Introduction to Information and Computer Science Databases and SQL Lecture b 5 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) Health IT Workforce Curriculum Version 3.0/Spring 2012 Contact Key PersonFirstName PersonLastName CoName CoAddress CoCity CoState 6.10 Table: Contact attributes (PD-US, 2012) Introduction to Information and Computer Science Databases and SQL Lecture b 6 Contact Table Key PersonFirst Name PersonLast Name CoName CoAddress CoCity 1 Bill Robeson Community Hospital, Inc. 1312 Main Portland OR 2 Albert Brookings Community Hospital Inc. 1312 Main St. Portland OR CoState 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 Health IT Workforce Curriculum Version 3.0/Spring 2012 Introduction to Information and Computer Science Databases and SQL Lecture b 7 Database Normalization • Prevent data inconsistency • Prevent update errors • Eliminate data redundancy Health IT Workforce Curriculum Version 3.0/Spring 2012 Introduction to Information and Computer Science Databases and SQL Lecture b 8 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) Health IT Workforce Curriculum Version 3.0/Spring 2012 Introduction to Information and Computer Science Databases and SQL Lecture b 9 New Tables Person Table ContactKey FirstName LastName CompanyKey 1 Bill Robeson 1 2 Albert Brookings 1 Company Table Company Key Name Address City State 1 Community Hospital, Inc. 1312 Main Portland OR 6.13 Tables: New tables using same data from Table 6.5 (PD-US, 2012) Health IT Workforce Curriculum Version 3.0/Spring 2012 Introduction to Information and Computer Science Databases and SQL Lecture b 10 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 Health IT Workforce Curriculum Version 3.0/Spring 2012 Introduction to Information and Computer Science Databases and SQL Lecture b 11 Building a Database • Database Management System Tools – Create tables – Create relationships – Control access – More… • Structured Query Language (SQL) – Database management – Access to data Health IT Workforce Curriculum Version 3.0/Spring 2012 Introduction to Information and Computer Science Databases and SQL Lecture b 12 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 Health IT Workforce Curriculum Version 3.0/Spring 2012 Introduction to Information and Computer Science Databases and SQL Lecture b 13 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). 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) Health IT Workforce Curriculum Version 3.0/Spring 2012 Introduction to Information and Computer Science Databases and SQL Lecture b 14