Sub-Queries in SQL SQL. 3 Types of Sub-Queries. 3 Types of Sub-Queries. Scalar Sub-Query Example. Scalar Sub-Query Example

Size: px
Start display at page:

Download "Sub-Queries in SQL SQL. 3 Types of Sub-Queries. 3 Types of Sub-Queries. Scalar Sub-Query Example. Scalar Sub-Query Example"

Transcription

1 SQL Sub-Queries in SQL Peter Y. Wu Department of Computer and Information Systems Robert Morris University Data Definition Language Create table for schema and constraints Drop table Data Manipulation Language (Update) Insert, Delete, Update Data Manipulation Language (Query) Select-from-where: simple queries with conditions Select-from-where: aggregate functions and grouping Select-from-where: multiple tables with JOIN operation Select-from-where: sub-queries 2 3 Types of Sub-Queries An SQL query generates a result table even when there is no data! Scalar: table with one column and one row. Vector: table with one column only. Table: any number of columns and rows. An SQL sub-query is an SQL query embedded inside an (outer) SQL query. 3 Types of Sub-Queries We can use sub-queries in different ways: Scalar: as if it is a scalar involved in a term of the where conditions. Vector: as if it is a list/set involved in quantified comparison in where conditions. Table: used in the from clause as a table. An SQL sub-query can be embedded many many levels deep. 3 4 Scalar Sub-Query Example Find the s who died the latest. We will need a scalar result from the database. Scalar Sub-Query Example We need a scalar value from the database to be used in a query Piece PNo PName CNo 1000 The Four Seasons B-minor Mass Christmas Oratorio Missa Solemnis Classical Symphony Cinderella 4 select CName from where Died = (select max(died) from ); The sub-query generates a scalar result a number for our use in the (outer) query. 5 6 (c) Peter Y Wu - RMU. 1

2 Vector Sub-Query The SQL Query generates a result table with exactly one column. We use the result table as a list/set for comparison in the (outer) Query. The Vector sub-query may or may not contain duplicates. Let us review the use of list/set for comparison in the where conditions. 7 Vector Sub-Query Example Find the s who was born the earliest. without using an aggregate function... Piece PNo PName CNo 1000 The Four Seasons B-minor Mass Christmas Oratorio Missa Solemnis Classical Symphony Cinderella 4 8 Vector Sub-Query Example We need to find the minimum from a list of values (under column Born in the table). select CName from where Born <= all (select Born from ); The sub-query generates a list also called a vector for use in the (outer) query. The sub-query is called a vector sub-query. Vector Sub-query: returning a list select CName from where Born <= all (select Born from ); Picks the earliest born composer select CName from where not(born > any (select Born from )); The two conditions are logically equivalent; the two SQL statements give the same result for any set of data. Also called a nested QUERY, with inner query (that is, the sub-query returning a set) in the outer query SQL: quantified list comparison Note that these operator pairs are equivalent: = any ( ) and not <> all ( ) > any ( ) and not < all ( ) < any ( ) and not > all ( ) >= any ( ) and not <= all ( ) <= any ( ) and not >= all ( ) 11 Vector Sub-Query Examples STUDENT ENROLLMENT SSN First Last SSN CNum John Smith Ann Miller David Meyer Mary Jones COURSE CNum Topic Title Instructor Enroll Information Systems Wood Data Structures Kovacs Database Management Wu Java Programming Wu Electronic Commerce Kovacs (c) Peter Y Wu - RMU. 2

3 Vector Sub-Query Examples STUDENT ENROLLMENT SSN First Last SSN CNum Section Term John Smith A Spring Ann Miller A Spring David Meyer A Spring Mary Jones A Spring 07 COURSE CNum Section Term Title Instructor Enroll 1050 A Spring 07 Information Systems Wood B Fall 08 Data Structures Kovacs A Spring 08 Database Systems Wu A Fall 07 Java Programming Wu A Spring 07 Electronic Commerce Kovacs SQL Query with multiple tables List the names of the students who are taking courses taught by instructor Wu. select s.first, s.last from student s, enrollment e, course c and e.cnum = c.cnum and e.section = c.section and e.term = c.term and c.instructor = Wu ; 14 SQL operators: in, not in Select from where <term> [not] in (<list>); <term> in (<list>) is true if the value of term is found in the set. (4240, 4770); or using a vector sub-query: (select CNum from course where Instructor = Wu ); 15 Sub-query: returning a list (select CNum from course where Instructor= Wu ); The sub-query returns the set of CNum s of courses taught by Instructor Wu. The outer query therefore lists the students who take courses taught by Instructor Wu. 16 SQL: quantified list comparison operators in ( ) and not in ( ) Select from where <term> in (<list>); is the same as Select from where <term> = any (<list>); Select from where <term> not in (<list>); is the same as Select from where <term> <> all (<list>); 17 SQL operator: exists Select from where [not] exists (<list>); select s.first, s.last from student s where not exists (select * from enrollment e ); Listing all students who are not enrolled in any course at all. 18 (c) Peter Y Wu - RMU. 3

4 Sub-query: union of two lists union (select CNum from course where Title like Data% ); The sets returned are unioned: listing all students who take courses taught by Wu OR courses with a title beginning with Data. 19 Sub-query: union of two lists select s.first, s.last from student s, enrollment e union (4240, 4770); A set is a list of terms, or a vector sub-query. Recall that <list> ::= <term>,, <term> <sub-query> 20 Sub-query: union all select s.first, s.last from student s, enrollment e union all (4240, 4770); will not remove duplicates, simply concatenate the two result sets may be more efficient. Duplicate removal can be quite expensive. 21 Use a generated table in the from clause. Same as using a view a table defined by an SQL query: the data depends on the base tables the query selects from. A special form of insert statement also uses a table sub-query see example. 22 Select CNo, CName, 1+floor(Born/100) as Century from ; CNo CName Century 1 Vivaldi 17 2 Bach 17 3 Mozart 18 4 Prokofiev 19 5 Dvorak CNo CName Century 1 Vivaldi 17 2 Bach 17 3 Mozart 18 4 Prokofiev 19 5 Dvorak 19 Select Century, count(cname) from (select CNo, CName, 1+floor(Born/100) as Century from ) group by Century; Century count(cname) (c) Peter Y Wu - RMU. 4

5 SQL: insert two forms TWO forms of insert statement: insert into <table-name> [ (<column>,, <column>) ] values (<expr>,, <expr>); insert into <table-name> [ (<column>,, <column>) ] ( <select-statement> ); SQL insert: using a table sub-query create table T2 (N1 integer, N2 integer); insert into T2 (N2,N1) select c1,c2 from T1; C1 T1 C N1 T2 N (c) Peter Y Wu - RMU. 5

Database Systems SQL. A.R. Hurson 323 CS Building

Database Systems SQL. A.R. Hurson 323 CS Building SQL A.R. Hurson 323 CS Building Structured Query Language (SQL) The SQL language has the following features as well: Embedded and Dynamic facilities to allow SQL code to be called from a host language

More information

Homework Assignment 2. Due Date: October 17th, CS425 - Database Organization Results

Homework Assignment 2. Due Date: October 17th, CS425 - Database Organization Results Name CWID Homework Assignment 2 Due Date: October 17th, 2017 CS425 - Database Organization Results Please leave this empty! 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 2.12 2.15 2.16 2.17 2.18 2.19 Sum

More information

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #3: SQL---Part 1

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #3: SQL---Part 1 CS 4604: Introduc0on to Database Management Systems B. Aditya Prakash Lecture #3: SQL---Part 1 Announcements---Project Goal: design a database system applica=on with a web front-end Project Assignment

More information

Relational Algebra and Calculus

Relational Algebra and Calculus Topics Relational Algebra and Calculus Linda Wu Formal query languages Preliminaries Relational algebra Relational calculus Expressive power of algebra and calculus (CMPT 354 2004-2) Chapter 4 CMPT 354

More information

Exam 1. March 12th, CS525 - Midterm Exam Solutions

Exam 1. March 12th, CS525 - Midterm Exam Solutions Name CWID Exam 1 March 12th, 2014 CS525 - Midterm Exam s Please leave this empty! 1 2 3 4 5 Sum Things that you are not allowed to use Personal notes Textbook Printed lecture notes Phone The exam is 90

More information

Database Applications (15-415)

Database Applications (15-415) Database Applications (15-415) Relational Calculus Lecture 5, January 27, 2014 Mohammad Hammoud Today Last Session: Relational Algebra Today s Session: Relational algebra The division operator and summary

More information

Functional Dependencies and Normalization. Instructor: Mohamed Eltabakh

Functional Dependencies and Normalization. Instructor: Mohamed Eltabakh Functional Dependencies and Normalization Instructor: Mohamed Eltabakh meltabakh@cs.wpi.edu 1 Goal Given a database schema, how do you judge whether or not the design is good? How do you ensure it does

More information

Design Theory: Functional Dependencies and Normal Forms, Part I Instructor: Shel Finkelstein

Design Theory: Functional Dependencies and Normal Forms, Part I Instructor: Shel Finkelstein Design Theory: Functional Dependencies and Normal Forms, Part I Instructor: Shel Finkelstein Reference: A First Course in Database Systems, 3 rd edition, Chapter 3 Important Notices CMPS 180 Final Exam

More information

Database Applications (15-415)

Database Applications (15-415) Database Applications (15-415) Relational Calculus Lecture 6, January 26, 2016 Mohammad Hammoud Today Last Session: Relational Algebra Today s Session: Relational calculus Relational tuple calculus Announcements:

More information

CS322: Database Systems Normalization

CS322: Database Systems Normalization CS322: Database Systems Normalization Dr. Manas Khatua Assistant Professor Dept. of CSE IIT Jodhpur E-mail: manaskhatua@iitj.ac.in Introduction The normalization process takes a relation schema through

More information

INTRODUCTION TO RELATIONAL DATABASE SYSTEMS

INTRODUCTION TO RELATIONAL DATABASE SYSTEMS INTRODUCTION TO RELATIONAL DATABASE SYSTEMS DATENBANKSYSTEME 1 (INF 3131) Torsten Grust Universität Tübingen Winter 2017/18 1 THE RELATIONAL ALGEBRA The Relational Algebra (RA) is a query language for

More information

Relational Algebra & Calculus

Relational Algebra & Calculus Relational Algebra & Calculus Yanlei Diao UMass Amherst Slides Courtesy of R. Ramakrishnan and J. Gehrke 1 Outline v Conceptual Design: ER model v Logical Design: ER to relational model v Querying and

More information

P Q1 Q2 Q3 Q4 Q5 Tot (60) (20) (20) (20) (60) (20) (200) You are allotted a maximum of 4 hours to complete this exam.

P Q1 Q2 Q3 Q4 Q5 Tot (60) (20) (20) (20) (60) (20) (200) You are allotted a maximum of 4 hours to complete this exam. Exam INFO-H-417 Database System Architecture 13 January 2014 Name: ULB Student ID: P Q1 Q2 Q3 Q4 Q5 Tot (60 (20 (20 (20 (60 (20 (200 Exam modalities You are allotted a maximum of 4 hours to complete this

More information

Schema Refinement & Normalization Theory: Functional Dependencies INFS-614 INFS614, GMU 1

Schema Refinement & Normalization Theory: Functional Dependencies INFS-614 INFS614, GMU 1 Schema Refinement & Normalization Theory: Functional Dependencies INFS-614 INFS614, GMU 1 Background We started with schema design ER model translation into a relational schema Then we studied relational

More information

Constraints: Functional Dependencies

Constraints: Functional Dependencies Constraints: Functional Dependencies Spring 2018 School of Computer Science University of Waterloo Databases CS348 (University of Waterloo) Functional Dependencies 1 / 32 Schema Design When we get a relational

More information

General Relativity by Robert M. Wald Chapter 2: Manifolds and Tensor Fields

General Relativity by Robert M. Wald Chapter 2: Manifolds and Tensor Fields General Relativity by Robert M. Wald Chapter 2: Manifolds and Tensor Fields 2.1. Manifolds Note. An event is a point in spacetime. In prerelativity physics and in special relativity, the space of all events

More information

Languages. Theory I: Database Foundations. Relational Algebra. Paradigms. Projection. Basic Operators. Jan-Georg Smaus (Georg Lausen)

Languages. Theory I: Database Foundations. Relational Algebra. Paradigms. Projection. Basic Operators. Jan-Georg Smaus (Georg Lausen) Languages Theory I: Database Foundations Jan-Georg Smaus (Georg Lausen) Paradigms 1. Languages: Relational Algebra Projection Union and Difference Summary 26.7.2011 Relational algebra Relational calculus

More information

SideNail. Martín Schonaker, Santiago Martínez

SideNail. Martín Schonaker, Santiago Martínez SideNail Martín Schonaker, Santiago Martínez March 24, 2010 2 Chapter 1 Quickstart 1.1 Hello, World! Listing 1.1 shows the simplest mapping example one can build with SideNail. The example shows how to

More information

You are here! Query Processor. Recovery. Discussed here: DBMS. Task 3 is often called algebraic (or re-write) query optimization, while

You are here! Query Processor. Recovery. Discussed here: DBMS. Task 3 is often called algebraic (or re-write) query optimization, while Module 10: Query Optimization Module Outline 10.1 Outline of Query Optimization 10.2 Motivating Example 10.3 Equivalences in the relational algebra 10.4 Heuristic optimization 10.5 Explosion of search

More information

Module 10: Query Optimization

Module 10: Query Optimization Module 10: Query Optimization Module Outline 10.1 Outline of Query Optimization 10.2 Motivating Example 10.3 Equivalences in the relational algebra 10.4 Heuristic optimization 10.5 Explosion of search

More information

Correlated subqueries. Query Optimization. Magic decorrelation. COUNT bug. Magic example (slide 2) Magic example (slide 1)

Correlated subqueries. Query Optimization. Magic decorrelation. COUNT bug. Magic example (slide 2) Magic example (slide 1) Correlated subqueries Query Optimization CPS Advanced Database Systems SELECT CID FROM Course Executing correlated subquery is expensive The subquery is evaluated once for every CPS course Decorrelate!

More information

But RECAP. Why is losslessness important? An Instance of Relation NEWS. Suppose we decompose NEWS into: R1(S#, Sname) R2(City, Status)

But RECAP. Why is losslessness important? An Instance of Relation NEWS. Suppose we decompose NEWS into: R1(S#, Sname) R2(City, Status) So far we have seen: RECAP How to use functional dependencies to guide the design of relations How to modify/decompose relations to achieve 1NF, 2NF and 3NF relations But How do we make sure the decompositions

More information

Relational Algebra 2. Week 5

Relational Algebra 2. Week 5 Relational Algebra 2 Week 5 Relational Algebra (So far) Basic operations: Selection ( σ ) Selects a subset of rows from relation. Projection ( π ) Deletes unwanted columns from relation. Cross-product

More information

Constraints: Functional Dependencies

Constraints: Functional Dependencies Constraints: Functional Dependencies Fall 2017 School of Computer Science University of Waterloo Databases CS348 (University of Waterloo) Functional Dependencies 1 / 42 Schema Design When we get a relational

More information

Normal Forms 1. ICS 321 Fall Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

Normal Forms 1. ICS 321 Fall Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa ICS 321 Fall 2013 Normal Forms 1 Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 9/16/2013 Lipyeow Lim -- University of Hawaii at Manoa 1 The Problem with

More information

Query Processing. 3 steps: Parsing & Translation Optimization Evaluation

Query Processing. 3 steps: Parsing & Translation Optimization Evaluation rela%onal algebra Query Processing 3 steps: Parsing & Translation Optimization Evaluation 30 Simple set of algebraic operations on relations Journey of a query SQL select from where Rela%onal algebra π

More information

CS5300 Database Systems

CS5300 Database Systems CS5300 Database Systems Relational Algebra A.R. Hurson 323 CS Building hurson@mst.edu This module is intended to introduce: relational algebra as the backbone of relational model, and set of operations

More information

Introduction to Data Management. Lecture #6 (Relational DB Design Theory)

Introduction to Data Management. Lecture #6 (Relational DB Design Theory) Introduction to Data Management Lecture #6 (Relational DB Design Theory) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Announcements v Homework

More information

INF1383 -Bancos de Dados

INF1383 -Bancos de Dados INF1383 -Bancos de Dados Prof. Sérgio Lifschitz DI PUC-Rio Eng. Computação, Sistemas de Informação e Ciência da Computação Projeto de BD e Formas Normais Alguns slides são baseados ou modificados dos originais

More information

Introduction to Data Management. Lecture #12 (Relational Algebra II)

Introduction to Data Management. Lecture #12 (Relational Algebra II) Introduction to Data Management Lecture #12 (Relational Algebra II) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Announcements v HW and exams:

More information

Design Theory for Relational Databases. Spring 2011 Instructor: Hassan Khosravi

Design Theory for Relational Databases. Spring 2011 Instructor: Hassan Khosravi Design Theory for Relational Databases Spring 2011 Instructor: Hassan Khosravi Chapter 3: Design Theory for Relational Database 3.1 Functional Dependencies 3.2 Rules About Functional Dependencies 3.3 Design

More information

Relational Algebra on Bags. Why Bags? Operations on Bags. Example: Bag Selection. σ A+B < 5 (R) = A B

Relational Algebra on Bags. Why Bags? Operations on Bags. Example: Bag Selection. σ A+B < 5 (R) = A B Relational Algebra on Bags Why Bags? 13 14 A bag (or multiset ) is like a set, but an element may appear more than once. Example: {1,2,1,3} is a bag. Example: {1,2,3} is also a bag that happens to be a

More information

General Overview - rel. model. Carnegie Mellon Univ. Dept. of Computer Science /615 DB Applications. Motivation. Overview - detailed

General Overview - rel. model. Carnegie Mellon Univ. Dept. of Computer Science /615 DB Applications. Motivation. Overview - detailed Carnegie Mellon Univ. Dep of Computer Science 15-415/615 DB Applications C. Faloutsos & A. Pavlo Lecture#5: Relational calculus General Overview - rel. model history concepts Formal query languages relational

More information

Database Systems Relational Algebra. A.R. Hurson 323 CS Building

Database Systems Relational Algebra. A.R. Hurson 323 CS Building Relational Algebra A.R. Hurson 323 CS Building Relational Algebra Relational model is based on set theory. A relation is simply a set. The relational algebra is a set of high level operators that operate

More information

Databases 2011 The Relational Algebra

Databases 2011 The Relational Algebra Databases 2011 Christian S. Jensen Computer Science, Aarhus University What is an Algebra? An algebra consists of values operators rules Closure: operations yield values Examples integers with +,, sets

More information

b. hurricanescale.xml - Information on the Saffir-Simpson Hurricane Scale [3].

b. hurricanescale.xml - Information on the Saffir-Simpson Hurricane Scale [3]. Background Information HOMEWORK INSTRUCTIONS Every year from June 1 to November 30 is hurricane season in the United States. Rescue relief agencies such as FEMA and the Red Cross are ready to assist when

More information

Intro to SQL. Two components. Data Definition Language (DDL): create table, etc. Data Manipulation Language (DML):

Intro to SQL. Two components. Data Definition Language (DDL): create table, etc. Data Manipulation Language (DML): Intro to SQL Two components Data Definition Language (DDL): create table, etc. Data Manipulation Language (DML): select, insert, delete, update, etc. The basic SELECT statement: Select From Where A1, A2,...AN

More information

Chapter 10. Normalization Ext (from E&N and my editing)

Chapter 10. Normalization Ext (from E&N and my editing) Chapter 10 Normalization Ext (from E&N and my editing) Outline BCNF Multivalued Dependencies and Fourth Normal Form 2 BCNF A relation schema R is in Boyce-Codd Normal Form (BCNF) if whenever an FD X ->

More information

b. states.xml Listing of states and their postal abbreviations.

b. states.xml Listing of states and their postal abbreviations. Background Information Mankind with all of its inventions and weapons has the false belief that it is in control of the environment. All too often the weather delivers a reminder that we are not invincible.

More information

Normal Forms (ii) ICS 321 Fall Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

Normal Forms (ii) ICS 321 Fall Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa ICS 321 Fall 2012 Normal Forms (ii) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 1 Hourly_Emps

More information

Query answering using views

Query answering using views Query answering using views General setting: database relations R 1,...,R n. Several views V 1,...,V k are defined as results of queries over the R i s. We have a query Q over R 1,...,R n. Question: Can

More information

GAV-sound with conjunctive queries

GAV-sound with conjunctive queries GAV-sound with conjunctive queries Source and global schema as before: source R 1 (A, B),R 2 (B,C) Global schema: T 1 (A, C), T 2 (B,C) GAV mappings become sound: T 1 {x, y, z R 1 (x,y) R 2 (y,z)} T 2

More information

Schema Refinement & Normalization Theory

Schema Refinement & Normalization Theory Schema Refinement & Normalization Theory Functional Dependencies Week 13 1 What s the Problem Consider relation obtained (call it SNLRHW) Hourly_Emps(ssn, name, lot, rating, hrly_wage, hrs_worked) What

More information

SCHEMA NORMALIZATION. CS 564- Fall 2015

SCHEMA NORMALIZATION. CS 564- Fall 2015 SCHEMA NORMALIZATION CS 564- Fall 2015 HOW TO BUILD A DB APPLICATION Pick an application Figure out what to model (ER model) Output: ER diagram Transform the ER diagram to a relational schema Refine the

More information

Introduction to Data Management. Lecture #7 (Relational DB Design Theory II)

Introduction to Data Management. Lecture #7 (Relational DB Design Theory II) Introduction to Data Management Lecture #7 (Relational DB Design Theory II) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Announcements v Homework

More information

Relational operations

Relational operations Architecture Relational operations We will consider how to implement and define physical operators for: Projection Selection Grouping Set operators Join Then we will discuss how the optimizer use them

More information

Schema Refinement and Normal Forms. Chapter 19

Schema Refinement and Normal Forms. Chapter 19 Schema Refinement and Normal Forms Chapter 19 1 Review: Database Design Requirements Analysis user needs; what must the database do? Conceptual Design high level descr. (often done w/er model) Logical

More information

Database Design and Normalization

Database Design and Normalization Database Design and Normalization Chapter 11 (Week 12) EE562 Slides and Modified Slides from Database Management Systems, R. Ramakrishnan 1 1NF FIRST S# Status City P# Qty S1 20 London P1 300 S1 20 London

More information

Databases Exam HT2016 Solution

Databases Exam HT2016 Solution Databases Exam HT2016 Solution Solution 1a Solution 1b Trainer ( ssn ) Pokemon ( ssn, name ) ssn - > Trainer. ssn Club ( name, city, street, streetnumber ) MemberOf ( ssn, name, city ) ssn - > Trainer.

More information

Schema Refinement. Feb 4, 2010

Schema Refinement. Feb 4, 2010 Schema Refinement Feb 4, 2010 1 Relational Schema Design Conceptual Design name Product buys Person price name ssn ER Model Logical design Relational Schema plus Integrity Constraints Schema Refinement

More information

CSC 261/461 Database Systems Lecture 10 (part 2) Spring 2018

CSC 261/461 Database Systems Lecture 10 (part 2) Spring 2018 CSC 261/461 Database Systems Lecture 10 (part 2) Spring 2018 Announcement Read Chapter 14 and 15 You must self-study these chapters Too huge to cover in Lectures Project 2 Part 1 due tonight Agenda 1.

More information

Introduction to Database Systems CSE 414. Lecture 20: Design Theory

Introduction to Database Systems CSE 414. Lecture 20: Design Theory Introduction to Database Systems CSE 414 Lecture 20: Design Theory CSE 414 - Spring 2018 1 Class Overview Unit 1: Intro Unit 2: Relational Data Models and Query Languages Unit 3: Non-relational data Unit

More information

Basic Logic and Proof Techniques

Basic Logic and Proof Techniques Chapter 3 Basic Logic and Proof Techniques Now that we have introduced a number of mathematical objects to study and have a few proof techniques at our disposal, we pause to look a little more closely

More information

CSE 132B Database Systems Applications

CSE 132B Database Systems Applications CSE 132B Database Systems Applications Alin Deutsch Database Design and Normal Forms Some slides are based or modified from originals by Sergio Lifschitz @ PUC Rio, Brazil and Victor Vianu @ CSE UCSD and

More information

Chapter 11, Relational Database Design Algorithms and Further Dependencies

Chapter 11, Relational Database Design Algorithms and Further Dependencies Chapter 11, Relational Database Design Algorithms and Further Dependencies Normal forms are insufficient on their own as a criteria for a good relational database schema design. The relations in a database

More information

Schema Refinement and Normal Forms. Why schema refinement?

Schema Refinement and Normal Forms. Why schema refinement? Schema Refinement and Normal Forms Why schema refinement? Consider relation obtained from Hourly_Emps: Hourly_Emps (sin,rating,hourly_wages,hourly_worked) Problems: Update Anomaly: Can we change the wages

More information

Schema Refinement: Other Dependencies and Higher Normal Forms

Schema Refinement: Other Dependencies and Higher Normal Forms Schema Refinement: Other Dependencies and Higher Normal Forms Spring 2018 School of Computer Science University of Waterloo Databases CS348 (University of Waterloo) Higher Normal Forms 1 / 14 Outline 1

More information

Relational algebra. Bence Molnár

Relational algebra. Bence Molnár Relational algebra Bence Molnár Introduction About relational algebra Basic properties of relational algebra: Well defined mathematical background Based on set theory Can be introduced through Armstrong

More information

Functional Dependency Theory II. Winter Lecture 21

Functional Dependency Theory II. Winter Lecture 21 Functional Dependency Theory II Winter 2006-2007 Lecture 21 Last Time Introduced Third Normal Form A weakened version of BCNF that preserves more functional dependencies Allows non-trivial dependencies

More information

Database Design and Implementation

Database Design and Implementation Database Design and Implementation CS 645 Schema Refinement First Normal Form (1NF) A schema is in 1NF if all tables are flat Student Name GPA Course Student Name GPA Alice 3.8 Bob 3.7 Carol 3.9 Alice

More information

Introduction to Data Management. Lecture #6 (Relational Design Theory)

Introduction to Data Management. Lecture #6 (Relational Design Theory) Introduction to Data Management Lecture #6 (Relational Design Theory) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Announcements v HW#2 is

More information

Data Bases Data Mining Foundations of databases: from functional dependencies to normal forms

Data Bases Data Mining Foundations of databases: from functional dependencies to normal forms Data Bases Data Mining Foundations of databases: from functional dependencies to normal forms Database Group http://liris.cnrs.fr/ecoquery/dokuwiki/doku.php?id=enseignement: dbdm:start March 1, 2017 Exemple

More information

Section Summary. Section 1.5 9/9/2014

Section Summary. Section 1.5 9/9/2014 Section 1.5 Section Summary Nested Quantifiers Order of Quantifiers Translating from Nested Quantifiers into English Translating Mathematical Statements into Statements involving Nested Quantifiers Translated

More information

Semester: Spring

Semester: Spring Eastern Mediterranean University Department of Mechanical Engineering LABORATORY WORK REPORT COURSE: MENG203 - Experimental Methods for Engineers Semester: Spring 2017-2018 EXPERIMENT No:1 Name of Experiment:

More information

Matrices. Chapter Definitions and Notations

Matrices. Chapter Definitions and Notations Chapter 3 Matrices 3. Definitions and Notations Matrices are yet another mathematical object. Learning about matrices means learning what they are, how they are represented, the types of operations which

More information

CIS Spring 2018 (instructor Val Tannen)

CIS Spring 2018 (instructor Val Tannen) CIS 160 - Spring 2018 (instructor Val Tannen) Lecture 09 Tuesday, February 13 PROOFS and COUNTING Figure 1: Too Many Pigeons Theorem 9.1 (The Pigeonhole Principle (PHP)) If k + 1 or more pigeons fly to

More information

A Dichotomy. in in Probabilistic Databases. Joint work with Robert Fink. for Non-Repeating Queries with Negation Queries with Negation

A Dichotomy. in in Probabilistic Databases. Joint work with Robert Fink. for Non-Repeating Queries with Negation Queries with Negation Dichotomy for Non-Repeating Queries with Negation Queries with Negation in in Probabilistic Databases Robert Dan Olteanu Fink and Dan Olteanu Joint work with Robert Fink Uncertainty in Computation Simons

More information

Instructor: Amol Deshpande

Instructor: Amol Deshpande Instructor: Amol Deshpande amol@cs.umd.edu } New topics to discuss More constructs in E/R modeling Conver@ng from E/R to rela@onal schema Crea@ng some E/R models Ruby on Rails } Other things Grading of

More information

Oracle Spatial: Essentials

Oracle Spatial: Essentials Oracle University Contact Us: 1.800.529.0165 Oracle Spatial: Essentials Duration: 5 Days What you will learn The course extensively covers the concepts and usage of the native data types, functions and

More information

HKBU: Tutorial 4

HKBU: Tutorial 4 COMP7640 @ HKBU: Tutorial 4 Functional Dependency and Database Normalization Wei Wang weiw AT cse.unsw.edu.au School of Computer Science & Engineering University of New South Wales October 17, 2014 Wei

More information

Lecture 24: Bloom Filters. Wednesday, June 2, 2010

Lecture 24: Bloom Filters. Wednesday, June 2, 2010 Lecture 24: Bloom Filters Wednesday, June 2, 2010 1 Topics for the Final SQL Conceptual Design (BCNF) Transactions Indexes Query execution and optimization Cardinality Estimation Parallel Databases 2 Lecture

More information

Functional Dependencies & Normalization. Dr. Bassam Hammo

Functional Dependencies & Normalization. Dr. Bassam Hammo Functional Dependencies & Normalization Dr. Bassam Hammo Redundancy and Normalisation Redundant Data Can be determined from other data in the database Leads to various problems INSERT anomalies UPDATE

More information

CS54100: Database Systems

CS54100: Database Systems CS54100: Database Systems Relational Algebra 3 February 2012 Prof. Walid Aref Core Relational Algebra A small set of operators that allow us to manipulate relations in limited but useful ways. The operators

More information

L13: Normalization. CS3200 Database design (sp18 s2) 2/26/2018

L13: Normalization. CS3200 Database design (sp18 s2)   2/26/2018 L13: Normalization CS3200 Database design (sp18 s2) https://course.ccs.neu.edu/cs3200sp18s2/ 2/26/2018 274 Announcements! Keep bringing your name plates J Page Numbers now bigger (may change slightly)

More information

www.lessonplansinc.com Topic: Dinosaur Evolution Project Summary: Students pretend to evolve two dinosaurs using genetics and watch how the dinosaurs adapt to an environmental change. This is a very comprehensive

More information

Relationships between elements of sets occur in many contexts. Every day we deal with

Relationships between elements of sets occur in many contexts. Every day we deal with C H A P T E R 9 Relations 9.1 Relations and Their Properties 9.2 n-ary Relations and Their Applications 9.3 Representing Relations 9.4 Closures of Relations 9.5 Equivalence Relations 9.6 Partial Orderings

More information

Exercises 1 - Solutions

Exercises 1 - Solutions Exercises 1 - Solutions SAV 2013 1 PL validity For each of the following propositional logic formulae determine whether it is valid or not. If it is valid prove it, otherwise give a counterexample. Note

More information

DATABASE DESIGN I - 1DL300

DATABASE DESIGN I - 1DL300 DATABASE DESIGN I - DL300 Fll 00 An introductory course on dtse systems http://www.it.uu.se/edu/course/homepge/dstekn/ht0/ Mnivskn Sesn Uppsl Dtse Lortory Deprtment of Informtion Technology, Uppsl University,

More information

Quiz 2. Due November 26th, CS525 - Advanced Database Organization Solutions

Quiz 2. Due November 26th, CS525 - Advanced Database Organization Solutions Name CWID Quiz 2 Due November 26th, 2015 CS525 - Advanced Database Organization s Please leave this empty! 1 2 3 4 5 6 7 Sum Instructions Multiple choice questions are graded in the following way: You

More information

Informationslogistik Unit 7: Conceptual Design of Databases Normalization

Informationslogistik Unit 7: Conceptual Design of Databases Normalization Informationslogistik Unit 7: Conceptual Design of Databases Normalization 17. V. 2011 Outline 1 Organization 2 SQL: Regular Expressions and Date Functions 3 Reminder and Overview 4 Normalization First

More information

Geographic Information Systems (GIS) - Hardware and software in GIS

Geographic Information Systems (GIS) - Hardware and software in GIS PDHonline Course L153G (5 PDH) Geographic Information Systems (GIS) - Hardware and software in GIS Instructor: Steve Ramroop, Ph.D. 2012 PDH Online PDH Center 5272 Meadow Estates Drive Fairfax, VA 22030-6658

More information

L14: Normalization. CS3200 Database design (sp18 s2) 3/1/2018

L14: Normalization. CS3200 Database design (sp18 s2)   3/1/2018 L14: Normalization CS3200 Database design (sp18 s2) https://course.ccs.neu.edu/cs3200sp18s2/ 3/1/2018 367 Announcements! Keep bringing your name plates J Outline today - More Normalization - Project 1

More information

Chapter 16. Logic Programming. Topics. Logic Programming. Logic Programming Paradigm

Chapter 16. Logic Programming. Topics. Logic Programming. Logic Programming Paradigm Topics Chapter 16 Logic Programming Introduction Predicate Propositions Clausal Form Horn 2 Logic Programming Paradigm AKA Declarative Paradigm The programmer Declares the goal of the computation (specification

More information

Section Summary. Predicates Variables Quantifiers. Negating Quantifiers. Translating English to Logic Logic Programming (optional)

Section Summary. Predicates Variables Quantifiers. Negating Quantifiers. Translating English to Logic Logic Programming (optional) Predicate Logic 1 Section Summary Predicates Variables Quantifiers Universal Quantifier Existential Quantifier Negating Quantifiers De Morgan s Laws for Quantifiers Translating English to Logic Logic Programming

More information

Profiling Sets for Preference Querying

Profiling Sets for Preference Querying Profiling Sets for Preference Querying Xi Zhang and Jan Chomicki Department of Computer Science and Engineering University at Buffalo, SUNY, U.S.A. {xizhang,chomicki}@cse.buffalo.edu Abstract. We propose

More information

Relational Database Design

Relational Database Design CSL 451 Introduction to Database Systems Relational Database Design Department of Computer Science and Engineering Indian Institute of Technology Ropar Narayanan (CK) Chatapuram Krishnan! Recap - Boyce-Codd

More information

CSE 303: Database. Outline. Lecture 10. First Normal Form (1NF) First Normal Form (1NF) 10/1/2016. Chapter 3: Design Theory of Relational Database

CSE 303: Database. Outline. Lecture 10. First Normal Form (1NF) First Normal Form (1NF) 10/1/2016. Chapter 3: Design Theory of Relational Database CSE 303: Database Lecture 10 Chapter 3: Design Theory of Relational Database Outline 1st Normal Form = all tables attributes are atomic 2nd Normal Form = obsolete Boyce Codd Normal Form = will study 3rd

More information

Schema Refinement and Normal Forms

Schema Refinement and Normal Forms Schema Refinement and Normal Forms UMass Amherst Feb 14, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke, Dan Suciu 1 Relational Schema Design Conceptual Design name Product buys Person price name

More information

Section 5.5: Matrices and Matrix Operations

Section 5.5: Matrices and Matrix Operations Section 5.5 Matrices and Matrix Operations 359 Section 5.5: Matrices and Matrix Operations Two club soccer teams, the Wildcats and the Mud Cats, are hoping to obtain new equipment for an upcoming season.

More information

Season Finale: Which one is better?

Season Finale: Which one is better? CS4310.01 Introduction to Operating System Spring 2016 Dr. Zhizhang Shen Season Finale: Which one is better? 1 Background In this lab, we will study, and compare, two processor scheduling policies via

More information

Database Normaliza/on. Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata

Database Normaliza/on. Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata Database Normaliza/on Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata Problems with redundancy Data (attributes) being present in multiple tables Potential problems Increase of storage

More information

Lecture #7 (Relational Design Theory, cont d.)

Lecture #7 (Relational Design Theory, cont d.) Introduction to Data Management Lecture #7 (Relational Design Theory, cont d.) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Announcements

More information

Schema Refinement and Normal Forms Chapter 19

Schema Refinement and Normal Forms Chapter 19 Schema Refinement and Normal Forms Chapter 19 Instructor: Vladimir Zadorozhny vladimir@sis.pitt.edu Information Science Program School of Information Sciences, University of Pittsburgh Database Management

More information

Department of Mathematics and Statistics Math B: Discrete Mathematics and Its Applications Test 1: October 19, 2006

Department of Mathematics and Statistics Math B: Discrete Mathematics and Its Applications Test 1: October 19, 2006 Department of Mathematics and Statistics Math 1019 3.0 B: Discrete Mathematics and Its Applications est 1: October 19, 2006 Name: (Last/amily) (irst) Student No. Instructions: 1. his test has 8 questions

More information

Basic Math Review for CS1340

Basic Math Review for CS1340 Basic Math Review for CS1340 Dr. Mihail January 15, 2015 (Dr. Mihail) Math Review for CS1340 January 15, 2015 1 / 34 Sets Definition of a set A set is a collection of distinct objects, considered as an

More information

Declarative Programming Techniques

Declarative Programming Techniques Declarative Programming Techniques Accumulators and Difference Lists (CTM 3.4.3-3.4.4) Carlos Varela RPI Adapted with permission from: Seif Haridi KTH Peter Van Roy UCL February 12, 2015 C. Varela; Adapted

More information

Schema Refinement and Normal Forms

Schema Refinement and Normal Forms Schema Refinement and Normal Forms Yanlei Diao UMass Amherst April 10 & 15, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke 1 Case Study: The Internet Shop DBDudes Inc.: a well-known database consulting

More information

Row Space, Column Space, and Nullspace

Row Space, Column Space, and Nullspace Row Space, Column Space, and Nullspace MATH 322, Linear Algebra I J. Robert Buchanan Department of Mathematics Spring 2015 Introduction Every matrix has associated with it three vector spaces: row space

More information

EECS-3421a: Test #2 Electrical Engineering & Computer Science York University

EECS-3421a: Test #2 Electrical Engineering & Computer Science York University 18 November 2015 EECS-3421a: Test #2 1 of 16 EECS-3421a: Test #2 Electrical Engineering & Computer Science York University Family Name: Given Name: Student#: CSE Account: Instructor: Parke Godfrey Exam

More information

Schema Refinement. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

Schema Refinement. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke Schema Refinement Yanlei Diao UMass Amherst Slides Courtesy of R. Ramakrishnan and J. Gehrke 1 Revisit a Previous Example ssn name Lot Employees rating hourly_wages hours_worked ISA contractid Hourly_Emps

More information