ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 10 – September 18, 2001
ICOM 6005Dr. Manuel Rodriguez Martinez2 Readings Read: –Chapter 3, The Relational Model of Data section and section 3.4 –Chapter 5, SQL: Queries, Programming, Triggers
ICOM 6005Dr. Manuel Rodriguez Martinez3 Relational Instance: Students sidnameloginagegpa Information about enrolled students
ICOM 6005Dr. Manuel Rodriguez Martinez4 Relational Instance: Courses cidsectionnameroom 80101English I English I English I Databases Databases Electronics Calculus276 Information about courses being offered
ICOM 6005Dr. Manuel Rodriguez Martinez5 Relational Instance: Registration cidsectionsid Information about student enrollment
ICOM 6005Dr. Manuel Rodriguez Martinez6 Projection Example Get the all the course ids and section numbers for all courses. –Answer: SELECT cid, section FROM Courses –In this case result is a set cidsection
ICOM 6005Dr. Manuel Rodriguez Martinez7 Projection Example 2 Get all the course ids for all courses. SELECT cid FROM Courses –In this case, result is not a set To make it a set: Get all the course id for all courses, removing duplicates SELECT distinct cid FROM Courses cid cid
ICOM 6005Dr. Manuel Rodriguez Martinez8 Generalized Projection Get the name and login domain for all students with GPA greater than The domain is a user-defined function that extract the domain part from a login address. –Ex. = ece SQL Query: SELECT name, domain(login) FROM Students WHERE gpa > 3.50 namedomain(login) Maryece Bobbyece Luzece
ICOM 6005Dr. Manuel Rodriguez Martinez9 Join Example Basic join format let’s you add the equi-join condition in the WHERE clause. Get the name, login id and gpa of all students enrolled in the course with cid 8010 SELECT S.name, S.login, S.gpa FROM Students S, Registration R WHERE S.sid = R.sid S.nameS.loginS.gpa
ICOM 6005Dr. Manuel Rodriguez Martinez10 Outer-Join Example
ICOM 6005Dr. Manuel Rodriguez Martinez11 Union Example
ICOM 6005Dr. Manuel Rodriguez Martinez12 Nested Queries