Component 4/Unit 6f Topic VI: Create simple querying statements for the database The SELECT statement Clauses Functions Joins Subqueries Data manipulation.

Slides:



Advertisements
Similar presentations
DB glossary (focus on typical SQL RDBMS, not XQuery or SPARQL)
Advertisements

Advanced SQL (part 1) CS263 Lecture 7.
A Guide to SQL, Seventh Edition. Objectives Use joins to retrieve data from more than one table Use the IN and EXISTS operators to query multiple tables.
Chapter 10: Designing Databases
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
What is a Database By: Cristian Dubon.
The Relational Model and Relational Algebra Nothing is so practical as a good theory Kurt Lewin, 1945.
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
Data Access Data Retrieval and Query Fundamentals.
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,
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Introduction to SQL J.-S. Chou Assistant Professor.
Introduction –All information systems create, read, update and delete data. This data is stored in files and databases. Files are collections of similar.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
Chapter 1 Overview of Database Concepts Oracle 10g: SQL
Database Technical Session By: Prof. Adarsh Patel.
Introduction to SQL Steve Perry
1 Chapter 1 Overview of Database Concepts. 2 Chapter Objectives Identify the purpose of a database management system (DBMS) Distinguish a field from a.
Web Services Week 8 Aims: –Using web services as front ends to databases Objectives: –Review of relational databases –Connecting to and querying databases.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
Lecture 2 An Overview of Relational Database IST 318 – DB Admin.
Introduction to SEQUEL. What is SEQUEL? Acronym for Structural English Query Language Acronym for Structural English Query Language Standard language.
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.
Databases and Statistical Databases Session 4 Mark Viney Australian Bureau of Statistics 5 June 2007.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
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.
Chapter 1Introduction to Oracle9i: SQL1 Chapter 1 Overview of Database Concepts.
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.
Component 4: Introduction to Information and Computer Science Unit 6a Databases and SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Component 4/Unit 6b Topic II Relational Databases Keys and relationships Data modeling Database acquisition Database Management System (DBMS) Database.
Component 4/Unit 6d Topic IV: Design a simple relational database using data modeling and normalization Description and Information Gathering Data Model.
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.
CS453: Databases and State in Web Applications (Part 2) Prof. Tom Horton.
SQL advanced select using Oracle 1. 2 Select Simple –data from a single table Advanced –data from more tables join sub-queries.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
Component 4: Introduction to Information and Computer Science Unit 6: Databases and SQL Lecture 6 This material was developed by Oregon Health & Science.
Oracle 10g Database Administrator: Implementation and Administration Chapter 10 Basic Data Management.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
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
SQL 101.
Contents Preface I Introduction Lesson Objectives I-2
Database Systems: Design, Implementation, and Management Tenth Edition
Presentation transcript:

Component 4/Unit 6f Topic VI: Create simple querying statements for the database The SELECT statement Clauses Functions Joins Subqueries Data manipulation

Getting Data Out of the DB The SQL SELECT statement is the common way to retrieve data from the DB Statements that are invoked to retrieve data are called queries The general form of the basic standard for the SELECT statement: SELECT attributename1, attributename2,... FROM tablename; Component 4/Unit 6f Health IT Workforce Curriculum Version 1.0/Fall

Example SELECT Statement SELECT InstName, InstContact From ClinicalTrialTestingInstitution; The above statement returns all the InstName values and associated InstContact values from the table. Component 4/Unit 6f Health IT Workforce Curriculum Version 1.0/Fall

The WHERE Clause SELECT InstName, InstContact FROM ClinicalTrialTestingInstitution WHERE InstContact = ‘ ’; The above statement returns the InstName and InstContact for only those rows where the contact is “ ” Component 4/Unit 6f Health IT Workforce Curriculum Version 1.0/Fall

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

Many More Clauses and Operators (these are for SQL Server) DistinctArithmetic (+, -, *, /, %/Modulo) LikeSign UnionNULL and IS NULL Intersect=, =, >, <> or != HavingUnderscore and % wildcards TopConcatenation (+) Group ByAND and OR NOTIn and Between (and more) Component 4/Unit 6f Health IT Workforce Curriculum Version 1.0/Fall

Functions SELECT COUNT(*) From ClinicalTrialTestingInstitution The above statement 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) Component 4/Unit 6f Health IT Workforce Curriculum Version 1.0/Fall

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) Component 4/Unit 6f Health IT Workforce Curriculum Version 1.0/Fall

Getting Data From More Than One Table Joining two or more tables together by using the primary-to-foreign keys relationship allows a query to get data from all tables that have been joined. Inner Joins Outer Joins Equi-Join Natural Join Component 4/Unit 6f Health IT Workforce Curriculum Version 1.0/Fall

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 Component 4/Unit 6f Health IT Workforce Curriculum Version 1.0/Fall

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 Component 4/Unit 6f Health IT Workforce Curriculum Version 1.0/Fall

Example Subquery Let’s say that we need to find the names of institutions in Denver, Colorado that have a trial cost resource of “NSF” We could write two separate SELECT statements and then manually compare the two outputs (projections) If you combine the two queries into a subquery the output should be just what we are looking for (nothing more and nothing less) Component 4/Unit 6f Health IT Workforce Curriculum Version 1.0/Fall

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’); Component 4/Unit 6f Health IT Workforce Curriculum Version 1.0/Fall

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; Component 4/Unit 6f Health IT Workforce Curriculum Version 1.0/Fall

Transaction Processing Multiple SQL statements executed as a unit Ability to back out changes within a transaction process (ROLLBACK and COMMIT) Component 4/Unit 6f Health IT Workforce Curriculum Version 1.0/Fall

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 Component 4/Unit 6f16 Health IT Workforce Curriculum Version 1.0/Fall 2010

Summary Continued Various problem anomalies are addressed in a database by splitting data into multiple tables. Primary and foreign keys are used to connect database tables together making retrieval of data from multiple tables possible Data modeling is used as a process in the development of a database design Component 4/Unit 6f17 Health IT Workforce Curriculum Version 1.0/Fall 2010

Summary Continued The entity relationship model shows entities, attributes and relationships. There are many normal forms that can be used in the normalization of a database, but typically only the first three are used. Component 4/Unit 6f18 Health IT Workforce Curriculum Version 1.0/Fall 2010

Summary Continued The database management system (DBMS) is responsible for maintaining the database and carrying out SQL statements There are 6 phases of database development: Specification gathering, testing, implementation, maintenance and modification Component 4/Unit 6f19 Health IT Workforce Curriculum Version 1.0/Fall 2010