Component 4: Introduction to Information and Computer Science Unit 6: Databases and SQL Lecture 6 This material was developed by Oregon Health & Science.

Slides:



Advertisements
Similar presentations
Advanced SQL (part 1) CS263 Lecture 7.
Advertisements

The Relational Model and Relational Algebra Nothing is so practical as a good theory Kurt Lewin, 1945.
Virtual training week 4 structured query language (SQL)
Structure Query Language (SQL) COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI.
Introduction to Structured Query Language (SQL)
Midterm Review Lecture 14b. 14 Lectures So Far 1.Introduction 2.The Relational Model 3.Disks and Files 4.Relational Algebra 5.File Org, Indexes 6.Relational.
Introduction to Structured Query Language (SQL)
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Introduction to Structured Query Language (SQL)
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
CSC 2720 Building Web Applications Database and SQL.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Concepts of Database Management Sixth Edition
Introduction to Information and Computer Science Databases and SQL Lecture b This material (Comp4_Unit6b) was developed by Oregon Health & Science University,
Introduction to Information and Computer Science
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Introduction to SQL J.-S. Chou Assistant Professor.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
Chapter 3 Single-Table Queries
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Database Technical Session By: Prof. Adarsh Patel.
Introduction to SQL Steve Perry
Component 4/Unit 6f Topic VI: Create simple querying statements for the database The SELECT statement Clauses Functions Joins Subqueries Data manipulation.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
Lecture 2 An Overview of Relational Database IST 318 – DB Admin.
Component 4: Introduction to Information and Computer Science Unit 6: Databases and SQL Lecture 2 This material was developed by Oregon Health & Science.
SQL advanced select using Oracle 1 7. Multiple Tables: Joins and Set Operations 8. Subqueries: Nested Queries.
SQL/Lesson 4/Slide 1 of 45 Using Subqueries and Managing Databases Objectives In this lesson, you will learn to: *Use subqueries * Use subqueries with.
SQL Server 7.0 Maintaining Referential Integrity.
Component 4: Introduction to Information and Computer Science Unit 6: Databases and SQL Lecture 4 This material was developed by Oregon Health & Science.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Quick review of SQL And conversion to Oracle SQL.
Oracle DML Dr. Bernard Chen Ph.D. University of Central Arkansas.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
Component 4: Introduction to Information and Computer Science Unit 6: Databases and SQL Lecture 3 This material was developed by Oregon Health & Science.
Component 4/Unit 6c Topic III Structured Query Language Background information What can SQL do? How is SQL executed? SQL statement characteristics What.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Component 4: Introduction to Information and Computer Science Unit 6a Databases and SQL.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
SQL advanced select using Oracle 1. 2 Select Simple –data from a single table Advanced –data from more tables join sub-queries.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
Introduction to Information and Computer Science
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
1 2 Concepts of Database Management, 4 th Edition, Pratt & Adamski Chapter 2 The Relational Model 1: Introduction, QBE, and Relational Algebra.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Introduction to Information and Computer Science Databases and SQL Lecture d This material (Comp4_Unit6d) was developed by Oregon Health & Science University,
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Introduction to Core Database Concepts Getting started with Databases and Structure Query Language (SQL)
BTM 382 Database Management Chapter 8 Advanced SQL Chitu Okoli Associate Professor in Business Technology Management John Molson School of Business, Concordia.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Relational Model.
Database Systems: Design, Implementation, and Management Tenth Edition
Introduction To Structured Query Language (SQL)
Index Note: A bolded number or letter refers to an entire lesson or appendix. A Adding Data Through a View ADD_MONTHS Function 03-22, 03-23,
Contents Preface I Introduction Lesson Objectives I-2
Chapter 8 Advanced SQL.
Database Systems: Design, Implementation, and Management Tenth Edition
Manipulating Data Lesson 3.
Presentation transcript:

Component 4: Introduction to Information and Computer Science Unit 6: Databases and SQL Lecture 6 This material 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 IU24OC

Topic VI: Create simple querying statements for the database The SELECT statement Clauses Functions Joins Subqueries Data manipulation Component 4/Unit Health IT Workforce Curriculum Version 2.0/Spring 2011

Getting Data Out of the Database The SQL SELECT statement is the common way to retrieve data Statements invoked to retrieve data are called queries The general form of the basic standard for the SELECT statement is: SELECT attributename1, attributename2,... FROM tablename; 3 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011

Example SELECT Statement This query returns all the InstName values and associated InstContact values from the named table: SELECT InstName, InstContact FROM ClinicalTrialTestingInstitution; 4 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011

The WHERE Clause This query returns the InstName and InstContact for only those rows where the contact is “ ”: SELECT InstName, InstContact FROM ClinicalTrialTestingInstitution WHERE InstContact = ‘ ’; 5 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011

The ORDER BY Clause The above statement will output the values for InstName and InstContact for rows with an institution contact of “ ” in alphabetical order on InstName: SELECT InstName, InstContact FROM ClinicalTrialTestingInstitution WHERE InstContact = ‘ ’ ORDER BY InstName; 6 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011

Many More Clauses and Operators (these are for SQL Server) DISTINCT Arithmetic (+, -, *, /, %/Modulo) LIKE Sign UNION NULL and IS NULL INTERSECT =, =, >, <> or != 7 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011 Underscore and % wildcards TOP Concatenation (+) GROUP BY HAVING AND and OR NOT IN and BETWEEN (and more)

Functions This query returns a count of all the rows in the table (since the primary key is InstName, this is the count of how many different institutions are in the table): SELECT COUNT(*) From ClinicalTrialTestingInstitution; 8 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011

There Are Many Different Functions (these are for SQL Server) ConvertMonths Between CastDateName SumABS AvgCeiling/Ceil and Floor Max, MinTrig functions Variance or VarpExp Stddev or stdevLog, Log10 and LN Date and TimePower (and many more) 9 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011

Getting Data From More Than One Table The join of two or more tables by using the primary-to-foreign key relationship allows a query to get data from all tables that have been joined. Inner Joins Equi-Join Natural Join Outer Joins 10 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011

Inner Join SELECT T.TrialCode, T.DrugNameFK, C.InstName, C.InstContact FROM ClinicalTrialTestingInstitution C, Trial T WHERE C.InstName = T.InstNameFK AND T.TrialCode < 4000; 11 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011

Subqueries One query’s results can be the input to another query. A query is nested within another query More than two levels of nesting are allowed 12 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011

Example Subquery Find the names of institutions in Denver, Colorado with a trial cost resource of “NSF” We could write two SELECT statements and then manually compare the two outputs If we combine the two queries the output should be just what we want. 13 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011

The Subquery SELECT C.InstName FROM ClinicalTrialTestingInstitution C WHERE C.City = ‘Denver’ AND C.State = ‘CO’ AND C.InstName IN (SELECT T.InstNameFK FROM Trial T WHERE T.TrialCostResource = ‘NSF’); 14 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011

Manipulation of Data Within the Database INSERT INSERT INTO Trial (TrialCode, TrialStartDate, DrugNameFK, InstNameFK) VALUES (39984, 09/20/2010, ‘Alaxamine’, ‘Acme Pharmaceuticals’); UPDATE UPDATE Trial SET TrialCostResource = ‘NSF’ WHERE TrialCode = 43895; DELETE DELETE FROM Trial WHERE TrialCode = 58340; 15 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011

Transaction Processing Multiple SQL statements executed as a unit.... all or nothing Ability to back out changes within a transaction process –ROLLBACK –COMMIT 16 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011

Summary A database has significant storage, efficiency and security advantages over other forms of storage. Data in a database is received, stored and retrieved via a Structured Query Language (SQL) also called a data sublanguage The database, tables, attributes, keys and relationships are created with SQL SQL can be placed in a transaction process and stored to be executed whenever appropriate 17 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011

Summary Continued Data modeling is a process in the development of a database design The entity relationship model shows entities, attributes and relationships. Primary and foreign keys are used to connect database tables together making retrieval of data from multiple tables possible 18 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011

Summary Continued Various anomalies are addressed in a database by splitting data into multiple tables. There are many normal forms that can be used in the normalization of a database, but typically only the first three are used. 19 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011

Summary Continued The Database Management System (DBMS) is used for maintaining the database and carrying out SQL statements There are six phases of database development: Specification gathering, design, testing, implementation, maintenance and modification 20 Component 4/Unit 6-6 Health IT Workforce Curriculum Version 2.0/Spring 2011