Relational Algebra and SQL Examples

Slides:



Advertisements
Similar presentations
Query Methods (SQL). What is SQL A programming language for databases. SQL (structured Query Language) It allows you add, edit, delete and run queries.
Advertisements

1 Advanced Database Systems Dr. Fatemeh Ahmadi-Abkenari February 2013.
1 Advanced Database Systems Dr. Fatemeh Ahmadi-Abkenari September 2013.
Database System - Assignment #3 Sept. 2012Yangjun Chen ACS Assignment #3 due Wed., Nov. 14, (30) Exercise 7.17 on Page 235 Show the result.
Relational Algebra and SQL Exercises
Relational Algebra Tim Kaddoura CS157A. Introduction  Relational query languages are languages for describing queries on a relational database  Three.
Relational Algebra and SQL Exercises Dr. Shiyong Lu Department of Computer Science Wayne State University ©copyright 2007, all rights.
Relational Algebra and SQL Exercises
BACS 485 Structured Query Language 2. BACS 485 SQL Practice Problems Assume that a database named COLLEGE exists. It contains the tables defined below.
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS Dr. Adam Anthony Fall 2012.
Quiz By: Steven Hancock Click START to begin the quiz. ALGEBRA.
McMillan’s Quizzes Multiple choice, open book, open notes Not open computers, not open classmates Partial credit: if less than half the class gets a question.
Exercise Exercise3.1 8 Exercise3.1 9 Exercise
1 Introduction to Information Systems SSC, Semester 6 Lecture 01.
Exercise Exercise Exercise Exercise
Exercise Exercise Exercise Exercise
Exercise Exercise6.1 7 Exercise6.1 8 Exercise6.1 9.
DATABASES AND TRANSACTION PROCESSING: An Application-Oriented Approach Lewis Bernstein Kifer © 2002 Addison Wesley.
Databases and Database Management System. 2 Goals comprehensive introduction to –the design of databases –database transaction processing –the use of.
1 Chapter 5 Relational Algebra and SQL. 2 Father of Relational Model Edgar F. Codd ( ) PhD from U. of Michigan, Ann Arbor Received Turing Award.
MBAC 611.  We have been using MS Access to query and modify our databases.  MS Access provides a GUI (Graphical User Interface) that hides much of the.
Create Forms Lesson 5. Software Orientation Creating Forms A form is a database object –enter, edit, or display data from a table or query Providing.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
CSc 2310 Principles of Programming (Java) Dr. Xiaolin Hu.
Algebra I Chapter 10 Review
Copyright© 2014, Sira Yongchareon Department of Computing, Faculty of Creative Industries and Business Lecturer : Dr. Sira Yongchareon ISCG 6425 Data Warehousing.
FEN  Data Definition: CREATE TABLE, ALTER TABLE  Data Manipulation: INSERT, UPDATE, DELETE  Queries: SELECT SQL: Structured Query Language.
If: What will the following be: And what about: Multiplying Terms or ?
1 Chapter 5 Relational Algebra and SQL. 2 Father of Relational Model Edgar F. Codd ( ) PhD from U. of Michigan, Ann Arbor Received Turing Award.
$1,000,000 $500,000 $100,000 $50,000 $10,000 $5000 $1000 $500 $200 $100 Is this your Final Answer? YesNo Question 2? Correct Answer Wrong Answer.
I want to do SQL, I start as if I am doing a regular query.
When I want to work with SQL, I start off as if I am doing a regular query.
Main MenuExercise Set 1Exercise Set 2 Interactive Exercises Set 1 Exercise 1.1 Exercise 1.2 Exercise 1.3.
1 CSE 480: Database Systems Lecture 12: SQL (Nested queries and Aggregate functions)
TODAY IN ALGEBRA…  Return Ch. 1 Test  Learning Goal: Review solutions to Ch. 1 test and how to do test corrections for credit up to 75%  See STATs for.
1 Chapter 5 Relational Algebra and SQL. 2 Father of Relational Model Edgar F. Codd ( ) PhD from U. of Michigan, Ann Arbor Received Turing Award.
CSCI 4333 Database Design and Implementation – Exercise (2) Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Factorization : Difference of Two Squares and Perfect Squares.
EXAMPLE 4 Solve linear systems with many or no solutions Solve the linear system. a.x – 2y = 4 3x – 6y = 8 b.4x – 10y = 8 – 14x + 35y = – 28 SOLUTION a.
CSCI 4333 Database Design and Implementation – Exercise (1) Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Which list of numbers is ordered from least to greatest? 10 –3, , 1, 10, , 1, 10, 10 2, 10 – , 10 –3, 1, 10, , 10 –3,
1 CSE 480: Database Systems Lecture 16: Relational Algebra.
CMPT 354 Database Management Systems Oliver Schulte
Introduction to CSCI 242 Compiled by S. Zhang 1. Syllabus Syllabus has the most updated information! –Use the information on the syllabus for the grading.
Retrieve the names of all senior students majoring in 'COSC' (computer science). SELECT Name FROM STUDENT WHERE Major='COSC'
1 Relational Algebra & SQL Query Formulation Exercise.
Database Management Systems
Database Systems – (
Mobile Applications (Android Programming)
Algebra substitution.
Dr. Shiyong Lu Wayne State Univesrity
Rule Exercises Status of the Ball Definitions and Rule 15
Rule Exercises Status of the Ball Definitions and Rule 15
Strategies for Revising and Editing passages:
BACK SOLUTION:
IS 220 Databases Fundamentals
Course Overview - Database Systems
التسعير الفصل الرابع عشر.
סדר דין פלילי – חקיקה ומהות ההליך הפלילי
Section 5.2 Study Materials
Equation Competition Each student will solve the equations.

Relational Algebra and SQL Exercises
June 2012 Living Environment Regents
January 2013 Living Environment Regents
You must show all steps of your working out.
Question 1.
Warmup Chapter P Review
Quiz Template Start quiz!
CSCI 4333 Database Design and Implementation – Exercise (1)
Presentation transcript:

Relational Algebra and SQL Examples Revised based on the notes from Dr. Shiyong Lu of Wayne State University Database Systems: An Application Oriented Approach, Edition 2 by Michael Kifer, Arthur Bernstein, Philip M. Lewis ISBN:0321268458 ISBN13:9780321268457 Release Date:March 2005

Relational Algebra and SQL Exercises Professor(ssn, profname, status) Course(crscode, crsname, credits) Taught(crsname, semester, ssn) Please refer to the SQLite commands that create the test database.

Query 1 Professor(ssn, profname, status) Course(crscode, crsname, credits) Taught(crsname, semester, ssn) Return those professors who have taught ‘CSCI203’ but never ‘CSCI240’.

Relational Algebra Solution Professor(ssn, profname, status) Course(crscode, crsname, credits) Taught(crsname, semester, ssn) ssn(crsname=‘CSCI203’(Taught)) -ssn(crsname=‘CSCI240’(Taught))

SQL Solution Professor(ssn, profname, status) Course(crscode, crsname, credits) Taught(crsname, semester, ssn) SELECT ssn From Taught Where crsname = ‘CSCI203’ EXCEPT Where crsname = ‘CSCI240’;

Query 2 Professor(ssn, profname, status) Course(crscode, crsname, credits) Taught(crsname, semester, ssn) Return those professors who have taught both ‘CSCI203’ and ‘CSCI204’.

Relational Algebra Solution Professor(ssn, profname, status) Course(crscode, crsname, credits) Taught(crsname, semester, ssn) ssn(crsname=‘CSCI203’  crsname=‘CSCI204’ (Taught), wrong! ssn(crsname=‘CSCI203’(Taught))  ssn(crsname=‘CSCI204’(Taught)), correct!

SQL Solution Professor(ssn, profname, status) Course(crscode, crsname, credits) Taught(crsname, semester, ssn) SELECT T1.ssn From Taught T1, Taught T2 Where T1.crsname = ‘CSCI203’ AND T2.crsname=‘CSCI204’ AND T1.ssn=T2.ssn;

Query 3 Return those professors who have never taught ‘CSCI204’. Professor(ssn, profname, status) Course(crscode, crsname, credits) Taught(crsname, semester, ssn) Return those professors who have never taught ‘CSCI204’.

Relational Algebra Solution Professor(ssn, profname, status) Course(crscode, crsname, credits) Taught(crsname, semester, ssn) ssn(crsname<>‘CSCI204’(Taught)), wrong answer! ssn(Professor) -ssn(crsname=‘CSCI204’(Taught)), correct answer!

SQL Solution Professor(ssn, profname, status) Course(crscode, crsname, credits) Taught(crsname, semester, ssn) SELECT ssn From Professor EXCEPT From Taught T Where T.crsname = ‘CSCI204’;