170 likes | 311 Views
ICOM 6005 – Database Management Systems Design. Dr. Manuel Rodr í guez-Mart í nez Electrical and Computer Engineering Department Lecture 8 – September 18, 2001. Readings. Read: Chapter 3, The Relational Model of Data section 3.1.1 and section 3.4
E N D
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 8 – September 18, 2001
Readings • Read: • Chapter 3, The Relational Model of Data • section 3.1.1 and section 3.4 • Chapter 5, SQL: Queries, Programming, Triggers Dr. Manuel Rodriguez Martinez
Relational Instance: Students Information about enrolled students Dr. Manuel Rodriguez Martinez
Relational Instance: Courses Information about courses being offered Dr. Manuel Rodriguez Martinez
Relational Instance: Registration Information about student enrollment Dr. Manuel Rodriguez Martinez
Renaming operator • Used to change the name of a relation and/or attributes in given relation • Useful to give to temporary relations results from relational expression. • Also good when two table have the attributes with the same names • Way to make attributes unique • Format (C(F), S) – rename relation S as C, and change attribute names in S as specified by rules in F. • F has the form {old_name1->new_name1, old_name2-> new_name2, …, old_nameN->new_nameN} • F can also be: F= {pos1 ->new_name1, pos2-> new_name2, … posN->new_nameN} Dr. Manuel Rodriguez Martinez
Renaming Operator • The F argument is optional, in which case, we only change the name of the relation. • The S can also be optional, but it just does not make sense. • When won’t follow this use • Examples: • Name students with gqa greater than 3.50 as Dean’s List: • Name cross product of Student and Courses PotentialRegistration Dr. Manuel Rodriguez Martinez
Rename operator • Change the name of sid field in Student to the name student_id Dr. Manuel Rodriguez Martinez
Structured Query Language (SQL) • Structured Query Language (SQL) is the most common language to write queries to be run on a DBMS • SQL was introduced by IBM as part of projects SEQUEL-XRM and System-R. • Provides a mechanism to express relational queries in a easy to understand fashion. • SQL is based on: • Relation algebra • Relation calculus (not covered here) Dr. Manuel Rodriguez Martinez
A Query in SQL • Get all students with gpa greater than 3.50. • Answer: SELECT * FROM Students S WHERE S.gpa > 3.50 • A query in SQL has the following structure: SELECT [Distinct] <Attribute-List> FROM <Table-List> WHERE <condition> Dr. Manuel Rodriguez Martinez
Selection Example Dr. Manuel Rodriguez Martinez
Projection Example Dr. Manuel Rodriguez Martinez
Generalized Projection Dr. Manuel Rodriguez Martinez
Join Example Dr. Manuel Rodriguez Martinez
Outer-Join Example Dr. Manuel Rodriguez Martinez
Union Example Dr. Manuel Rodriguez Martinez
Nested Queries Dr. Manuel Rodriguez Martinez