Download presentation
Presentation is loading. Please wait.
Published byArlene Anderson Modified over 9 years ago
1
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj RM/SQL Lecture 3 © Akhilesh Bajaj, 2000, 2002, 2004. All Rights Reserved.
2
Review of Lectures 1 & 2 Learnt the basics of the relational model Learnt the notions of superkeys, candidate keys and primary keys Relational algebra - The select operation - The project operation -The assignment operation - The union operation - The set difference operation - The intersect operation - The cartesian product operation - The natural join operation
3
Goals for Today Practise relational algebra - Discussion in class (questions from you!) - In-class assignment Get started with SQL
4
Discussion & Questions from You
5
Relational Schema For Example Relational Algebra Queries Professors (f_id, f_name, f_address, f_specialty, highest_degree) Courses (c_id, c_name, num_credits) Sections (c_id, s_id, time_held, week_days_held, date_began, date_ended, cl_id) Students (st_id, st_name, gender, st_gpa) Grades (st_id, c_id, s_id, grade) Classrooms (cl_id, capacity, location) Teach (f_id, c_id, s_id)
6
In-Class Assignment Example 1 Information on all Professors who have a Ph.D. degree and specialize in “Databases”.
7
In-Class Assignment Example 2 Names and number of credits of all courses being completely taught between “Jun-17-2003” and “Aug-15-2003”. What if the course was at least partially taught between those dates?
8
date_began >= ‘JUN-17-2003’ AND ‘date_ended<= ‘AUG-15-2003’ date_ended >= ‘JUN-17-2003’ AND ‘date_began<= ‘AUG-15-2003’ First Query (only courses completely taught in the period) Second Query (courses that are at least partially taught in the period) -------------------------------------------------------- (Course spanned whole summer) --------------------| (Course started before summer but ended in the summer) (Course started in summer but ended after summer) | ---------------------------- |---------------------------------------| (Time line for summer) JUN 17, 2003 Aug, 15, 2003
9
In-Class Assignment Example 3 Names and faculty_ids of all Professors who are teaching or have taught at least once in classrooms that have a capacity of > 100. What if we wanted names and faculty ids of professors who have only ever taught in classrooms with capacity > 100?
10
In-Class Assignment Example 4 Names and GPAs of all students who have an ‘A’ in MIS3053ASpr2008(c_id=“MIS3053”, s_id = “ASpr2008”) What if we wanted Names and GPAs of all students who have an ‘A’ or a ‘B’ in MIS3053ASpr2008 (c_id=“MIS3053”, s_id = “ASpr2008”)
11
In-Class Assignment Example 5 Names of all Professors who teach the student ”Johnny Jones”. What if we wanted names of all professors who are only currently teaching “Johnny Jones”.
12
In-Class Assignment Example 6 Names of all students and Professors who go to class (or have gone to class) at 8:00 am.
13
In-Class Assignment Example 7 Names of all Professors who have never given a “C” grade. If we look at the schema, we see that names are not unique. What if we had 5 professors called “Bob”, 3 of whom had given a ‘C’ at least once, but 2 had not. Would “Bob” show up in our query?
14
Why is Relational Algebra Important For Us The backbone relational database query language. The examples so far have hopefully shown how it can be used to ask ad-hoc questions of the database. The things we learnt here are supported in SQL. E.g., the UNION, the INTERSECT, the cartesian product operations. Relational Algebra is a great way to VISUALIZE the query as it is being run. Knowing relational algebra will allow us to get a better understanding of SQL queries, since they are built using relational algebra concepts (and then some more concepts!!)
15
Structured Query Language (SQL) The standard relational database language Used to query the database (hardest to learn!), defining the relational schema, inserting, deleting and modifying data in the database. Two standards exist: SQL-89 and SQL-92. Most systems support at least SQL-89. SQL is the standard language with which we interact with the relational database system. SQL was invented in the early 1970-s. It has been around for around 25 years, and likely to be around for decades ahead.
16
Structured Query Language (SQL): Query Part To use SQL for querying, we need a defined relational schema. SQL allows the use of null values. The basic query clause in SQL is the select from where Condition ; clause. Note that the select here is similar to the project in relational algebra. The where here is similar to the select in relational algebra.
17
Structured Query Language (SQL): Query Part Example: Information on all Professors who have a Ph.D. degree and specialize in “Databases”.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.