© Jalal Kawash 2010 3 Database Queries Peeking into Computer Science.

Slides:



Advertisements
Similar presentations
Structured Query Language (SQL)
Advertisements

What is a Database By: Cristian Dubon.
Basic SQL Introduction Presented by: Madhuri Bhogadi.
Virtual training week 4 structured query language (SQL)
Relational Databases Chapter 4.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 8 Foundations of Relational Implementation.
James Tam Databases In this section of notes you will learn about: different types of databases, how information is stored in databases, the different.
Introduction to Structured Query Language (SQL)
Structured query language This is a presentation by JOSEPH ESTRada on the beauty of Structured Query Language.
Introduction to Structured Query Language (SQL)
© 2002 by Prentice Hall 1 SI 654 Database Application Design Winter 2003 Dragomir R. Radev.
Concepts of Database Management Sixth Edition
CORE 2: Information systems and Databases STORAGE & RETRIEVAL 2 : SEARCHING, SELECTING & SORTING.
INFORMATION TECHNOLOGY IN BUSINESS AND SOCIETY SESSION 16 – SQL SEAN J. TAYLOR.
DAY 16: ACCESS CHAPTER 2 Tazin Afrin October 10,
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
© Jalal Kawash Programming Peeking into Computer Science 1.
SQL 資料庫查詢語言 取材自 EIS, 3 rd edition By Dunn et al..
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Concepts of Database Management Seventh Edition
© Jalal Kawash 2010 Logic Peeking into Computer Science.
CIS 103 — Applied Computer Technology Last Edited: September 17, 2010 by C.Herbert Using Database Management Systems.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
Database Queries. Queries Queries are questions used to retrieve information from a database. Contain criteria to specify the records and fields to be.
© Jalal Kawash Databases & Data Modelling Peeking into Computer Science.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Examining data using Microsoft Access Queries Using Criteria and Calculations SESSION 3.2 This section covers specifying an exact match condition in a.
© Jalal Kawash 2010 Elementary Set Theory Peeking into Computer Science.
Concepts of Database Management Seventh Edition
“INTRODUCTION TO DATABASE AND SQL”. Outlines 2  Introduction To Database  Database Concepts  Database Properties  What is Database Management System.
5-1 McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
© Jalal Kawash Programming Peeking into Computer Science 1.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Information Building and Retrieval Using MySQL Track 3 : Basic Course in Database.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
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.
Variables and control statements in PL\SQL Chapter 10.
IS 380 Introduction to SQL This lectures covers material from: database textbook chapter 3 Oracle chapter: 3,14,17.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
Lesson 13 Databases Unit 2—Using the Computer. Computer Concepts BASICS - 22 Objectives Define the purpose and function of database software. Identify.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
© Jalal Kawash Database Queries Peeking into Computer Science.
SQL.. AN OVERVIEW lecture3 1. Overview of SQL 2  Query: allow questions to be asked of the data and display only the information required. It can include.
(SQL - Structured Query Language)
Chapter 3: Relational Databases
SQL Introduction to database and SQL. Chapter 1: Databases and Database Users 6 Introduction to Databases Databases touch all aspects of our lives. Examples:
Presentation on Database management Submitted To: Prof: Rutvi Sarang Submitted By: Dharmishtha A. Baria Roll:No:1(sem-3)
1 CS 430 Database Theory Winter 2005 Lecture 13: SQL DML - Modifying Data.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
SQL. Structured Query Language ( SQL is a language of database, it includes database creation, deletion, fetching rows and modifying rows etc. ) SQL is.
CHAPTER 7 DATABASE ACCESS THROUGH WEB
SQL Query Getting to the data ……..
“Introduction To Database and SQL”
MySQL Subquery Source: Dev.MySql.com
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Introduction To Database Systems
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
Chapter 2 Database Environment.
SQL .. An overview lecture3.
Chapter 8 Advanced SQL.
DATABASE Purpose of database
Database SQL.
Human and Computer Interaction (H.C.I.) &Communication Skills
Presentation transcript:

© Jalal Kawash Database Queries Peeking into Computer Science

© Jalal Kawash 2010Peeking into Computer Science Reading Assignment Mandatory: Chapter 4 – Sections 4.6 & 4.7 2

© Jalal Kawash 2010Peeking into Computer Science Example Access DB Can be found on: Includes all examples in the book ◦Numbered by exercise numbers 3

Structured Query Language 4

© Jalal Kawash 2010Peeking into Computer Science Objectives By the end of this section, you will be able to: 1. Name the two parts of SQL 2. Understand the function of each part 3. Formulate basic DDL & DML statements in SQL

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Purpose To store & retrieve information Database: Customer information Sale $$$

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Queries Queries are questions ‘asked’ of/to the database in order to retrieve information. 7

© Jalal Kawash 2009Peeking into Computer Science JT’s Extra: Retrieving Data Via Queries Data retrieval occurs through the use of ‘queries’: – A query is a question asked of the data in the database. – Typically worded to show only the parts of the database for which the answer to the question is true. – Example 1: What is the SIN, name and pay rate of every employee in the Employees Table: – Example 2: What employees have the last name of Morris? Query

© Jalal Kawash 2010Peeking into Computer Science Structured Query Language SQL Programming language, specialized for databases Data Definition Language (DDL) ◦Defining the structure of the DB Data Manipulation Language (DML) ◦Manipulating the contents of the DB 9 JT’s Extra: SQL = Structured Query Language JT’s Extra: Creating the data (table) What fields? What will each field store? JT’s Extra: Modifying the data (table) Insertions Deletions

© Jalal Kawash 2010Peeking into Computer Science DDL 10

© Jalal Kawash 2010Peeking into Computer Science DDL 11 DROP TABLE EMPLOYEE

© Jalal Kawash 2010Peeking into Computer Science Access Table Creation 12

© Jalal Kawash 2009Peeking into Computer Science JT’s Extra: DML General Structure Recall: Data manipulation language modifies the tables General format: into/from Example: Insert into Employees {some values} Delete from Employees {conditions for deletion }

© Jalal Kawash 2010Peeking into Computer Science DML - Insertion 14

© Jalal Kawash 2010Peeking into Computer Science DML - Deletion 15

© Jalal Kawash 2010Peeking into Computer Science Access Insertion and Deletion 16

SQL Queries Questioning the database 17

© Jalal Kawash 2010Peeking into Computer Science Objectives By the end of this section, you will be able to: 1. Know the basic parts of speech in SQL 2. Formulate SQL queries 3. Use set operations in SQL queries 4. Use complex logic in SQL queries

© Jalal Kawash 2010Peeking into Computer Science Example Database 19

© Jalal Kawash 2010Peeking into Computer Science Queries Questions submitted to the DB Query By Example (QBE) Using SQL 20

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Basic Format Of SQL Queries Informal English description Given some condition(s) is/are met what columns of what tables will appear. Example: If last name is “Morris” show the employee number, first name and last name from the employees table. 21

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Basic Format Of SQL Queries (2) Specifying the query in the form of QBE (Query by example) in MS-Access 22

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Basic Format Of SQL Queries (3) Formal SQL structure SELECT FROM WHERE ORDER BY Optional section: used to format or rank query results

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Example SQL Query SELECT ◦Employees.EmployeeNumber, ◦Employees.FirstName, ◦Employees.LastName FROM EMPLOYEES WHERE EMPLOYEES.LastName="Morris"; 24

© Jalal Kawash 2010Peeking into Computer Science QBE – Projection 25

© Jalal Kawash 2010Peeking into Computer Science SQL - Projection 26 X X

© Jalal Kawash 2010Peeking into Computer Science QBE - Selection 27

© Jalal Kawash 2010Peeking into Computer Science SQL - Selection 28

© Jalal Kawash 2009Peeking into Computer Science JT’s Extra: Using The Wildcard In Queries The ‘wildcard’ character can stand for any number of characters in the position that it’s placed: ◦Example queries that follow will be from the Employees table:

© Jalal Kawash 2009Peeking into Computer Science JT’s Extra: Using The Wildcard In Queries (Access) Examples: – Which employees have a last name that begins with ‘m’? – Which employees have a last name ends with ‘s’?

© Jalal Kawash 2009Peeking into Computer Science 31 – Which employees have the letter ‘a’ anywhere in their first name? JT’s Extra: Using The Wildcard In Queries (Access: 2)

© Jalal Kawash 2010Peeking into Computer Science Wild Cards 32 *

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Set Operations On Databases UNION INTERSECT MINUS

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Union (Logical “OR”) 34

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Intersection (Logical “AND”) 35 (203 student) AND (Women)

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Subtraction “Minus” 36

© Jalal Kawash 2010Peeking into Computer Science JT’s Extra: Forming SQL Queries Using The Set Operations Format: 37 SET OPERATION

© Jalal Kawash 2010Peeking into Computer Science SQL – Set Operations 38

© Jalal Kawash 2010Peeking into Computer Science SQL – Set Operations 39

© Jalal Kawash 2010Peeking into Computer Science SQL – Set Operations 40

© Jalal Kawash 2010Peeking into Computer Science Union in Access Cannot be done in design view, only in SQL view 41

© Jalal Kawash 2010Peeking into Computer Science SQL – Set Operations 42

© Jalal Kawash 2010Peeking into Computer Science SQL – Set Operations 43

© Jalal Kawash 2010Peeking into Computer Science INTERSECT and MINUS in Access No direct support Can use IN for intersect Can use NOT IN for Minus 44

© Jalal Kawash 2010Peeking into Computer Science INTERSECT in Access 45

© Jalal Kawash 2010Peeking into Computer Science How IN Works 46 Result

© Jalal Kawash 2010Peeking into Computer Science MINUS in Access 47

© Jalal Kawash 2010Peeking into Computer Science Comparison Operators Equals = Not equal != Greater > Greater or equal >= Less than < Less than or equal <= 48

© Jalal Kawash 2010Peeking into Computer Science Boolean Operators AND OR NOT 49

© Jalal Kawash 2010Peeking into Computer Science SQL – Example Query 50

© Jalal Kawash 2010Peeking into Computer Science QBE – Example Query 51

© Jalal Kawash 2010Peeking into Computer Science SQL – Example Query 52

© Jalal Kawash 2010Peeking into Computer Science SQL – Example Query 53

© Jalal Kawash 2010Peeking into Computer Science QBE – Example Query 54 JT: >30000

© Jalal Kawash 2009Peeking into Computer Science JT’s Extra: Empty Queries (Contradiction) Take care not to specify queries that can never be true! (Logic: contradiction) This will result in an “Empty Query”, a query that yields no results. – Example: Which employees have a gross pay lower than $1,000 AND higher than $2,000 (inclusive for both) on one of their time cards? Query Result of the (empty) query Wav file from “The Simpson” © Fox

© Jalal Kawash 2009Peeking into Computer Science JT’s Extra: Queries Resulting From A Tautology In a similar fashion take care not to specify queries that are always true. (Tautology) Query SELECT Employees.YearsOfService, Employees.LastName, Employees.FirstName FROM Employees WHERE (((Employees.YearsOfService)>=10)) OR (((Employees.YearsOfService)<=20)); SQL Query result