This document introduces relational databases and some basic concepts. It provides examples of student and course tables and describes primary keys that uniquely identify rows and foreign keys that link tables. It also demonstrates selection and projection operations on tables as well as joins to combine information from multiple tables.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
57 views
Helping Relational Data Base
This document introduces relational databases and some basic concepts. It provides examples of student and course tables and describes primary keys that uniquely identify rows and foreign keys that link tables. It also demonstrates selection and projection operations on tables as well as joins to combine information from multiple tables.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 12
Introduction to Relational
Databases An Example Table • Students (sid: string, name: string, login: string, age: integer, gpa: real)
sid name login age gpa
50000 Dave dave@cs 19 3.3 53666 Jones jones@cs 18 3.4 53688 Smith smith@ee 18 3.2 53650 Smith smith@math 19 3.8 53831 Madayan madayan@music 11 1.8 53832 Guldu guldu@music 12 2.0 Another example: Courses • Courses (cid, instructor, quarter, dept) cid instructo quarter Dept sid r 50000 Carnatic10 Jane Fall 06 Music 1 53666 Reggae20 Bob Summer Music 53688 3 06 53650 Topology1 Mary Spring 06 Math 53831 01 History105 Alice Fall 06 History 53832 Keys • Primary key – minimal subset of fields that is unique identifier for a tuple – sid is primary key for Students – cid is primary key for Courses • Foreign key –connections between tables – Courses (cid, instructor, quarter, dept) – Students (sid, name, login, age, gpa) – How do we express which students take each course? • In general, need a new table Enrolled(cid, grade, studid) Studid is foreign key that references sid in Student table Student Foreign Enrolled key sid name login
cid grade studid 50000 Dave dave@cs
53666 Jones jones@cs Carnatic101 C 53831 53688 Smith smith@ee Reggae203 B 53832 53650 Smith smith@math 53831 Madayan madayan@musi Topology112 A 53650 53832 Guldu guldu@music History 105 B 53666 Basic operators • Selection – return rows that meet some condition • Projection – return column values • Join Selection Select students with gpa higher than 3.3 from S1: σgpa>3.3(S1) S1 sid name gpa 50000 Dave 3.3 sid name gpa 53666 Jones 3.4 53666 Jones 3.4 53688 Smith 3.2 53650 Smith 3.8 53650 Smith 3.8 53831 Madayan 1.8 53832 Guldu 2.0 Projection Project name and gpa of all students in S1: name, gpa(S1) S1 Sid name gpa name gpa 50000 Dave 3.3 Dave 3.3 53666 Jones 3.4 Jones 3.4 53688 Smith 3.2 Smith 3.2 53650 Smith 3.8 Smith 3.8 53831 Madayan 1.8 Madayan 1.8 53832 Guldu 2.0 Guldu 2.0 Combine Selection and Projection • Project name and gpa of students in S1 with gpa higher than 3.3: name,gpa(σgpa>3.3(S1))
Sid name gpa
50000 Dave 3.3 name gpa 53666 Jones 3.4 Jones 3.4 53688 Smith 3.2 Smith 3.8 53650 Smith 3.8 53831 Madayan 1.8 53832 Guldu 2.0 Example: Intersection S1 S2 sid name gpa sid name gpa 50000 Dave 3.3 53666 Jones 3.4 53666 Jones 3.4 53688 Smith 3.2 53688 Smith 3.2 53700 Tom 3.5 53650 Smith 3.8 53777 Jerry 2.8 53831 Madayan 1.8 53832 Guldu 2.0 53832 Guldu 2.0 sid name gpa 53666 Jones 3.4 S1 S2 = 53688 Smith 3.2 53832 Guldu 2.0 Joins • Combine information from two or more tables • Example: students enrolled in courses: S1 S1.sid=E.studidE S1 Sid name gpa E 50000 Dave 3.3 cid grade studid 53666 Jones 3.4 Carnatic101 C 53831 53688 Smith 3.2 Reggae203 B 53832 53650 Smith 3.8 Topology112 A 53650 53831 Madayan 1.8 History 105 B 53666 53832 Guldu 2.0 S1 Joins Sid name gpa E 50000 Dave 3.3 cid grade studid 53666 Jones 3.4 Carnatic101 C 53831 53688 Smith 3.2 Reggae203 B 53832 53650 Smith 3.8 Topology112 A 53650 53831 Madayan 1.8 History 105 B 53666 53832 Guldu 2.0 sid name gpa cid grade studid 53666 Jones 3.4 History105 B 53666 53650 Smith 3.8 Topology112 A 53650 53831 Madayan 1.8 Carnatic101 C 53831 53832 Guldu 2.0 Reggae203 B 53832