ppt 2 dbms
ppt 2 dbms
σP (R)
Select Operation
• Select those tuples of the loan relation where the branch is
“Perryridge,” we write
σbranch-name =“Perryridge” (loan)
• We can find all tuples in which the loan amount is more than
1200Rs. by writing
σamount>1200 (loan)
Select Operation
• In general, we allow comparisons using =, ≠ , < , ≤ , >, ≥ in the
selection predicate.
Πcustomer_name(borrower )
Πcustomer_name(depositor)
Composition of Relational Operations
• The result of a relational operation is itself a relation.
For Example:
Πcustomer_name(σcustomer-city =“Indore”(customer))
Union Operation
• Find the names of all bank customers who have either an account
or a loan or both.
• To answer the query, we need the union of two sets; that is, we
need all customer names that appear in either or both of the two
relations.
1. The relations r and s must be of the same arity. That is, they
must have the same number of attributes.
Πcustomer-name(depositor) − Πcustomer-name(borrower )
Set Difference Operation
• As with the union operation, we must ensure that set
differences are taken between compatible relations. Therefore,
for a set difference operation r − s to be valid, If,
• Consider the query “Find the names of all customers who have
a loan at the bank, along with the loan number and the loan
amount.”
Natural-Join Operation
• To solve this query, we first form the Cartesian product of the
borrower and loan relations. Then, we select those tuples that
pertain to only the same loan-number, followed by the
projection of the resulting customer-name, loan-number, and
amount.
• There are actually three forms of the operation: left outer join,
denoted by , right outer join denoted by and full outer
join, denoted by
• All three forms of outer join compute the join, and add extra
tuples to the result of the join.
Left Outer Join
• The left outer join takes all tuples in the left relation that
did not match with any tuple in the right relation, pads the
tuples with null values for all other attributes from the right
relation, and adds them to the result of the natural join.
• All information from the left relation is present in the result of
the left outer join.
Right Outer Join
• The right outer join is symmetric with the left outer join: It
pads tuples from the right relation that did not match any from
the left relation with nulls and adds them to the result of the
natural join.
• All information from the right relation is present in the result
of the right outer join.
Full Outer Join
• The full outer join does both of those operations, padding
tuples from the left relation that did not match any from the
right relation, as well as tuples from the right relation that did
not match any from the left relation, and adding them to the
result of the join.
Modifications of the Database
Deletion
• We can delete only whole tuples; we cannot delete values on
only particular attributes.
r←r−E
• The model was first proposed by Dr. E.F. Codd of IBM in 1970 in
the following paper: "A Relational Model for Large Shared Data
Banks," Communications of the ACM, June 1970.
• Let R S1 X S2
Table Relation
Column Attribute/Domain
Row Tuple
Values in a column Domain
Table Definition Schema of a Relation
Populated Table Extension
Example
CHARACTERISTICS OF RELATIONS
• Ordering of tuples in a relation r(R): The tuples are not
considered to be ordered, even though they appear to be in the
tabular form.
or..
(2) a null.
In case (2), the FK in R1 should not be a part of its own primary
key.
Exercise
• Consider the following relations for a database that keeps
track of student enrollment in courses and the books adopted
for each course:
• STUDENT(SSN, Name, Bdate)
• COURSE(Course#, Cname, Dept)
• ENROLL(SSN, Course#, Quarter, Grade)
• BOOK_ADOPTION(Course#, Quarter, Book_ISBN)
• TEXT(Book_ISBN, Book_Title, Publisher, Author)
• Draw a relational schema diagram specifying the foreign
keys for this schema.
The Tuple Relational Calculus
• The tuple relational calculus, by contrast, is a nonprocedural
query language.
• It describes the desired information without giving a specific
procedure for obtaining that information.
• A query in the tuple relational calculus is expressed as
{t | P(t)}
• that is, it is the set of all tuples t such that predicate P is true
for t.
• Following our earlier notation, we use t[A] to denote the value
of tuple t on attribute A, and we use t ∈ r to denote that tuple t
is in relation r.
Example