The operators take one or two relations as inputs and produce a new
relation as a result.
1. Selection Operation:
- it is unary operations.
- it is represented by the lower Greek letter sigma. ( ) )) )
- Syntax: <selection-condition>(<Relation>)
-Notation: p(r)
-p is called the selection predicate
- Defined as:p(r) = {t | t r and p(t)}
Where p is a formula in propositional calculus consisting of terms
Connected by: (and), (or), (not)
Each term is one of: <attribute> op <attribute> or <constant>
Where op is one of: =, , >, . <.
-Example of selection:
branch_name=Perryridge(account)
2. Project Operation
-Notation: where A1, A2 are attribute names and r is a relation name.n the
result is defined as the relation of k columns obtained by erasing the
columns that are not listed
-Duplicate rows removed from result, since relations are sets
-Example: To eliminate the branch_name attribute of account
account_number, balance (account)
3. Union Operation
Notation: r s
-Defined as:r s = {t | t r or t s}
-For r s to be valid.
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
- Assume that attributes of r(R) and s(S) are disjoint. (That is, R S = ).
- If attributes of r(R) and s(S) are not disjoint, then renaming must be used.
Cartesian product Operation Example
Relations r, s:
rXs
Example Queries:
Q1.Find all loans of over $1200
Ans: amount > 1200 (loan)
Q2.Find the loan number for each loan of an amount greater than $1200
amount > 1200 (loan)
ns: loan_number (amount > 1200 (loan))
Q3.Find the names of all customers who have a loan, an account, or both,
from the bank
ns: customer_name (borrower) customer_name (depositor)
Q4. Find the names of all customers who have a loan at the Perryridge
Branch
Ans: customer_name (branch_name=Perryridge
(borrower.loan_number = loan.loan_number(borrower x loan)))
Q5. Find the names of all customers who have a loan at the
Perryridge branch but do not have an account at any branch of
the bank.
Ans: customer_name (branch_name = Perryridge
(borrower.loan_number = loan.loan_number(borrower x loan)))
customer_name(depositor)
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
Q6. Find the names of all customers who have a loan at the Perryridge
branch.
Ans: customer_name (branch_name = Perryridge (
borrower.loan_number = loan.loan_number (borrower x loan)))
Formal Definition:
A basic expression in the relational algebra consists of either one of the
following:
-A relation in the database
-A constant relation
- Let E1 and E2 be relational algebra expressions; the following are all
relational algebra expressions:
-E1 E2
-E1 E2
-E1 x E2
-p (E1), P is a predicate on attributes in E1
-s (E1), S is a list consisting of some of the attributes in E1
- x (E1), x is the new name for the result of E1
Additional Operations
We define additional operations that do not add any power to the
Relational algebra, but that simplifies common queries.
-Set intersection
- Natural join
- Division
- Assignment
Set Intersection Operation:
Notation: r s
Defined as: r s = { t | t r and t s }
Assume: r, s have the same arty attributes of r and s are compatible
Note: r s = r (r s)
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
Right Outer Join: take all the tuples from right relation and match with left
relation, which didnt match with all the attributes with left relation.
Relational Calculus Languages:
-Tuple Relational Calculus
-Domain Relational Calculus
-QuerybyExample (QBE)
Tuple Rellational Calculus:
-A nonprocedural query language, where each query is of the form
{t | P (t ) }
- It is the set of all tuples t such that predicate P is true for t
- t is a tuple variable, t [A ] denotes the value of tuple t on attribute A
- t r denotes that tuple t is in relation r
- P is a formula similar to that of the predicate calculus.
Banking Example
Branch (branch_name, branch_city, assets )
Customer (customer_name, customer_street, customer_city )
Account (account_number, branch_name, balance )
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
Armstrong Axioms
- Let F be a set of functional dependency the closure of F is the
set of all functional dependencies logically implied by F.
- We denoted the closure of F by F+.
- We can find the F+ given by F by using following rule.
- A) Reflexive rule
- B)Augmentation rule
- C) Transitive Rule
- These three rule are sound because do not generate any
incorrect functional dependency.
- The three rules are complete because for a given set F of FD
and they allowed generate all F+.
- These three rules is known as Armstrong Rules.
I. Reflexive Rule:
- if are the set of attributes and then is FD.
- Proof: let t1 and t2 be the two tuples of relations R such that
t1[]=t2[]
It means that all the attributes of t1 and t2 are same.
Then is another set of set attributes which is subset of .
so t1[]=t2[]
So is FD.
II. Augmentation Rule:
If is a FD and r is set of attributes the rr is FD.
Proof: let t1, t2 be the two tuples of relation R.
Let us assume that the FD r->r is not FD in a relation R.
Since -> is satisfied on R so we get t1 [] =t2 [] -------- (1)
t1[]=t2[] ------------(2)
since rr does not hold on Relation R
t1[r]=t2[r]---------------(3)
t1[r]=t2[r]----------------(4)
from equ(1) and (3)
we get t1[r]->t2[r]--------(5)
from equ(2) and (5)
t1[r]=t2[r]---------------(6)
from equ(3) and (6) we get r->r (proved)
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
Database normalization
Normalization is the process of efficiently organizing data in a
database. There are two goals of the normalization process:
eliminating redundant data (for example, storing the same data in
more than one table) and ensuring data dependencies make sense
(only storing related data in a table). Both of these are worthy goals
as they reduce the amount of space a database consumes and
ensure that data is logically stored.
First Normal Form - 1NF:
First normal form (1NF) sets the very basic rules for an organized
database:
Eliminate duplicative columns from the same table.
Create separate tables for each group of related data and identify
each row with a unique column or set of columns (the primary
key).
The first normal form only says that the table should only include
atomic values, i.e. one value per box. For example, we cannot in
Table 1 below put in both Volvo and SAAB in the same box even if
we buy cars from both suppliers. We must use to different rows for
storing that. In most RDBMSs it is not allowed to assign more than
one value to each box that result in that all tables are in first
normal form.
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
Important Points
Functional dependency
In a given table, an attribute Y is said to have a functional
dependency on a set of attributes X (written X Y) if and only if
each X value is associated with precisely one Y value. For example,
in an "Employee" table that includes the attributes "Employee ID"
and "Employee Date of Birth", the functional dependency {Employee
ID} {Employee Date of Birth} would hold. It follows from the
previous two sentences that each {Employee ID} is associated with
precisely one {Employee Date of Birth}.
Trivial functional dependency
- Let R is a relation and FD -- is trival dependency if
- A Fd is said to be trival functional dependency they are
satisfied all relations.
- AA,ABA
A trivial functional dependency is a functional dependency of an
attribute on a superset of itself. {Employee ID, Employee Address}
{Employee Address} is trivial, as is {Employee Address} {Employee
Address}.
Full functional dependency
An attribute is fully functionally dependent on a set of attributes X
if it is:
functionally dependent on X, and
not functionally dependent on any proper subset of X.
{Employee Address} has a functional dependency on
{Employee ID, Skill}, but not a full functional dependency,
because it is also dependent on {Employee ID}.
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
Transitive dependency
A transitive dependency is an indirect functional dependency, one
in which XZ only by virtue of XY and YZ.
Multivalued dependency
A multivalued dependency is a constraint according to which the
presence of certain rows in a table implies the presence of certain
other rows.
Join dependency
A table T is subject to a join dependency if T can always be
recreated by joining multiple tables each having a subset of the
attributes of T.
Superkey
A superkey is a combination of attributes that can be used to
uniquely identify a database record. A table might have many
superkeys.
Candidate key
A candidate key is a special subset of superkeys that do not have
any extraneous
Non-prime attribute
A non-prime attribute is an attribute that does not occur in any
candidate key. Employee Address would be a non-prime attribute in
the "Employees' Skills" table.
Prime attribute:A prime attribute, conversely, is an attribute that
does occur in some candidate key.
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
Primary key
Most DBMSs require a table to be defined as having a single unique
key, rather than a number of possible unique keys. A primary key is
a key which the database designer has designated for this purpose.
Query Processing
Query processing refer to no of activity involved in retrieve or
extracting data from database.
- Transfer query in High level language (SQL) into Low level
language (Relational algebra)
- Execute to retrieve of data.
Query Optimization: query optimizer is the process of selecting the
most efficient query among many strategies, i.e. usually possible for
processing.
- Query optimization reduces the execution time of query.
- Scanner, Parser, and validator
Internal representation of query
Plan
Generation
Cost
Estimation
Execute query
Query code generator
Code execute in query
Run-time database
processor.
Result query
System catalogue
manager
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n