DBMS - Module2 - Till Cross Product
DBMS - Module2 - Till Cross Product
Module: 2
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 1
Relational Model Concepts
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 2
Basic Idea of Relational Model
• The data elements in each row represent certain facts that correspond to a real-world
entity or relationship
• In the formal model, rows are called tuples
• Each column has a column header that gives an indication of the meaning of the data
items in that column
• In the formal model, the column header is called an attribute name (or just attribute)
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 3
Relational Model Concepts
• The table is called relation (or) simply, a table is a collections of related attributes and there is a
relation among the attributes.
• The relational model is today the primary data model for commercial data processing
applications.
• A relational database consists of a collection of tables, each of which is assigned a unique name.
• A row in a table represents a relationship among a set of values. Since a table is a collection of
such relationships, there is a close correspondence between the concept of table and the
mathematical concept of relation, from which the relational data model takes its name.
• Thus, in the relational model the term relation is used to refer to a table, while the term tuple is
used to refer to a row. Similarly, the term attribute refers to a column of a table.
4
Example of a Relation
attributes
(or columns)
tuples
(or rows)
5
Basic structure
• Formally, given sets D1, D2, …. Dn, a relation r is a subset of D1 x D2 x … x. Dn
Thus a relation is a set of n-tuples (a1, a2, …, an) where each ai ∈ Di
Example: if
customer-name = {Jones, Smith, Curry, Lindsay}
customer-street = {Main, North, Park}
customer-city = {Harrison, Rye, Pittsfield}
6
Example
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 7
Schema Definition
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 8
Domain Definition
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 9
Tuple definition
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 10
Relation State
• The relation state is a subset of the Cartesian product of the domains of its attributes
• each domain contains the set of all possible values the attribute can take.
• Example: attribute Cust-name is defined over the domain of character strings of
maximum length 25
• dom(Cust-name) is varchar(25)
• The role these strings play in the CUSTOMER relation is that of the name of a customer.
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 11
Relation- Attribute , Domain and Degree
• Each attribute Ai is the name of a role played by some domain D in the relation schema
R.
• A relation schema is used to describe a relation; R is called the name of this relation.
• The degree (or arity) of a relation is the number of attributes n of its relation schema.
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 12
Relation Model-Notations
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 13
Terms in RDBMS
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 14
Characteristics Of Relations
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 15
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 16
Characteristics of Relations
2. Ordering of attributes in a relation schema R (and of values within each tuple) does not
require this ordering
• But for ease of handling, we will consider the attributes in R(A1, A2, ..., An) and the
values in t=<v1, v2, ..., vn> to be ordered .
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 17
Characteristics Of Relations
3. Values in a tuple:
• All values are considered atomic (indivisible).
• Each value in a tuple must be from the domain of the attribute for that column
• If tuple t = <v1, v2, …, vn> is a tuple (row) in the relation state r of R(A1, A2,
…, An)
• Then each vi must be a value from dom(Ai)
• A special null value is used to represent values that are unknown or inapplicable to
certain tuples
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 18
MCQs
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 19
3. In RDBMS terminology a table is called a …………..
a)Range b)domain c)relation d)tuple
Answer option b
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 20
Relational Model Constraints
• In a relational database, there will typically be many relations, and the tuples in those
relations are usually related in various ways.
• The state of the whole database will correspond to the states of all its relations at a
particular point in time.
• There are generally many restrictions or constraints on the actual values in a database
state
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 21
Categories of constraints on databases
1. Inherent model-based constraints or implicit constraints: Constraints that are
inherent in the data model
2. Schema-based constraints or explicit constraints : Constraints that can be directly
expressed in the schemas of the data model by specifying them in the DDL
3. Application-based or semantic constraints or business rules : Constraints that
cannot be directly expressed in the schemas of the data model, and hence must be
expressed and enforced by the application programs
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 22
Schema based constraints
• Domain constraints
• Key constraints
• Constraints on NULLs
• Entity integrity constraints
• Referential integrity constraints.
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 23
Domain Constraints
• Domain constraints specify that within each tuple, the value of each attribute A must be an
atomic value from the domain dom(A).
• The data types associated with domains typically include standard numeric data types for
integers (such as short integer, integer, and long integer) and real numbers (float and
double-precision float).
• Characters, Booleans, fixed-length strings, and variable-length strings are also available,
as are date, time, timestamp, and other special data types.
• Domains can be even enumerated data types.
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 24
Key Constraints
• Superkey of R:
• Is a set of attributes SK of R with the following condition:
• No two tuples in any valid relation state r(R) will have the same value for SK
• That is, for any distinct tuples t1 and t2 in r(R), t1[SK] t2[SK]
• This condition must hold in any valid state r(R)
• A superkey SK specifies a uniqueness constraint that no two distinct tuples in any state r
of R can have the same value for SK.
• Every relation has at least one default superkey— the set of all its attributes.
• Eg. {Ssn, Name, Age},{SSN,Name,Address},{SSN,Name}
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 25
Key
• A "minimal" superkey
• That is, a key is a superkey K such that removal of any attribute from K results in a
set of attributes that is not a superkey (does not possess the superkey uniqueness
property)
• {Ssn, Name, Age} {Ssn}
• In general, any super key formed from a single attribute is also a key.
• A key with multiple attributes must require all its attributes together to have the
uniqueness property.
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 26
Candidate Key
• A relation schema may have more than one key. In this case, each of the keys is called a
candidate key.
• Eg.
• One of the candidate keys is designated as the primary key of the relation
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 27
Constraints on NULLs
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 28
Sample Dataset
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 29
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 30
Referential Integrity
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 31
Foreign Key – Formal Definition
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 32
Schema Diagram with Foreign Key
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 33
Referential Integrity Constraints in Company
Database
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 34
Other Constraints
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 35
State Constraints and Transition Constraints
• All constraints discussed so far are state constraints since it is applicable on any valid
state,
• Transition constraints can be defined to deal with state changes in the database.
• An example of a transition constraint is: “the salary of an employee can only increase.”
• Such constraints are typically enforced by the application programs or specified using
active rules and triggers
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 36
Foreign key representation : Another Example
37
Update Operations, Transactions,
and Dealing with Constraint Violations
• There are mainly 3 update operations basically possible on dataset in ant database
• Insert
• Delete
• Update
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 38
In case of integrity violation, several actions can be taken
• Cancel the operation that causes the violation (RESTRICT or REJECT option)
• Perform the operation but inform the user of the violation
• Trigger additional updates so the violation is corrected (CASCADE option, SET
NULL option)
• Execute a user-specified error-correction routine
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 39
Sample Dataset
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 40
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 41
Insertion Operation
• INSERT may violate any of the constraints:
• Domain constraint:
• if one of the attribute values provided for the new tuple is not of the specified
attribute domain
• Key constraint:
• if the value of a key attribute in the new tuple already exists in another tuple in
the relation
• Referential integrity:
• if a foreign key value in the new tuple references a primary key value that does
not exist in the referenced relation
• Entity integrity:
• if the primary key value is null in the new tuple
• Insertion operation will be just rejected if any of the attribute violates defined constraints
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 42
Operation:
Delete the WORKS_ON tuple with
Essn = ‘999887777’ and Pno = 10.
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 46
• Operation:
• Delete the EMPLOYEE tuple with Ssn = ‘999887777’.
• Result: This deletion is not acceptable, because there are tuples in WORKS_ON that
refer to this tuple.
• Hence, if the tuple in EMPLOYEE is deleted, referential integrity violations will result.
• Operation:
• Delete the EMPLOYEE tuple with Ssn = ‘333445555’.
• Result: This deletion will result in even worse referential integrity violations, because the
tuple involved is referenced by tuples from the EMPLOYEE,DEPARTMENT,
WORKS_ON, and DEPENDENT relations.
Delete Operation
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 49
When to use the option?
ON DELETE CASCADE
• A foreign key with cascade delete means that if a record in the parent table is deleted, then
the corresponding records in the child table will automatically be deleted.
• This option is specified when this FK is also a part of PK in child relation
ON DELETE SET NULL
• If set null option is specified on the foreign key, if the primary key in parent is deleted
corresponding referring tuples values will be set to null.
• This option can be specified if the FK is not part the PK of the table
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 50
Update Operation
• UPDATE may violate domain constraint and NOT NULL constraint on an attribute being
modified
• Any of the other constraints may also be violated, depending on the attribute being
updated:
• Updating the primary key (PK):
• Similar to a DELETE followed by an INSERT
• Need to specify similar options to DELETE
• Updating a foreign key (FK):
• May violate referential integrity
• Updating an ordinary attribute (neither PK nor FK):
• Can only violate domain constraints
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 51
Transaction
• This concept is relevant in the context where multiple users and/or application programs
are accessing and updating the database concurrently.
• A transaction is a logical unit of work that may involve several accesses and/or updates to
the database (such as what might be required to reserve several seats on an airplane
flight).
• The point is that, even though several transactions might be processed concurrently, the
end result must be as though the transactions were carried out sequentially.
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 52
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, Major, 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.
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 53
SOLUTION
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 54
RELATIONAL ALGEBRA
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 55
RELATIONAL ALGEBRA
• Relational algebra is the basic set of operations for the relational model
• These operations enable a user to specify basic retrieval requests (or queries)
• The result of an operation is a new relation, which may have been formed from one or
more input relations
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 56
What is an Algebra?
A language based on operators and a domain of values.
Operators map values taken from the domain into other domain values.
Hence, an expression involving operators and arguments produces a value in the domain.
When the domain is a set of all relations (and the operators are as described later), we get
the relational algebra
We refer to the expression as a query and the value produced as the query result.
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 57
• The algebra operations thus produce new relations
• These can be further manipulated using operations of the same algebra
• A sequence of relational algebra operations forms a relational algebra expression
• The result of a relational algebra expression is also a relation that represents the result
of a database query (or retrieval request)
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 58
Relational Algebra consists of several groups of operations
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 60
Unary Relational Operations: SELECT
• The SELECT operation (denoted by (sigma)) is used to select a subset of the tuples from a
relation based on a selection condition.
• The selection condition acts as a filter
• Keeps only those tuples that satisfy the qualifying condition
• Tuples satisfying the condition are selected whereas the other tuples are discarded
(filtered out)
• Examples:
• Select the EMPLOYEE tuples whose department number is 4:
DNO = 4 (EMPLOYEE)
• Select the employee tuples whose salary is greater than $30,000:
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 61
• In general, the select operation is denoted by <selection condition>(R)
where
• the symbol (sigma) is used to denote the select operator
• the selection condition is a Boolean (conditional) expression specified on the attributes
of relation R
• tuples that make the condition true are selected
• appear in the result of the operation
• tuples that make the condition false are filtered out
• discarded from the result of the operation
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 62
SELECT Operation Properties
• The SELECT operation <selection condition>(R) produces a relation S that has the same schema
(same attributes) as R
• SELECT is commutative:
• <condition1>( < condition2> (R)) = <condition2> ( < condition1> (R))
• Because of commutativity property, a cascade (sequence) of SELECT operations may be
applied in any order:
• <cond1>(<cond2> (<cond3> (R)) = <cond2> (<cond3> (<cond1> ( R)))
• A cascade of SELECT operations may be replaced by a single selection with a conjunction
of all the conditions:
• <cond1>(< cond2> (<cond3>(R)) = <cond1> AND < cond2> AND < cond3>(R)))
• The number of tuples in the result of a SELECT is less than (or equal to) the number
of tuples in the input relation R
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 63
EXAMPLE
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 64
ANOTHER EXAMPLE
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 65
VARIOUS OPERATORS IN SELECTION LOGIC
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 66
FIND EMPLOYEES AGED MORE THAN 30 AND
SALARY>40000
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 67
FIND THE CITIZENS WHOSE RESIDENCE AND PLACE OF
BIRTH ARE SAME
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 68
Unary Relational Operations: PROJECT
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 69
PROJECT
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 70
PROJECT Operation Properties
• The number of tuples in the result of projection <list>(R) is always less or equal
to the number of tuples in R
• If the list of attributes includes a key of R, then the number of tuples in the result of
PROJECT is equal to the number of tuples in R
• PROJECT is not commutative
• <list1> ( <list2> (R) ) = <list1> (R) as long as <list2> contains the attributes in <list1>
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 71
EXAMPLE
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 72
RELATIONAL ALGREBRA EXPRESSIONS
• We may want to apply several relational algebra operations one after the other
• Either we can write the operations as a single relational algebra expression by nesting
the operations, or
• We can apply one operation at a time and create intermediate result relations.
• In the latter case, we must give names to the relations that hold the intermediate results.
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 73
Single expression versus sequence of relational operations
(Example)
• To retrieve the first name, last name, and salary of all employees who work in
department number 5, we must apply a select and a project operation
• We can write a single relational algebra expression as follows:
• FNAME, LNAME, SALARY( DNO=5(EMPLOYEE))
• OR We can explicitly show the sequence of operations, giving a name to each
intermediate relation:
• DEP5_EMPS DNO=5(EMPLOYEE)
• RESULT FNAME, LNAME, SALARY (DEP5_EMPS)
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 74
Select id,name from person where Hobby=‘stamps’ OR
Hobby=‘coins’;
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 75
Unary Relational Operations: RENAME
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 76
RENAME Operation
• The general RENAME operation can be expressed by any of the following forms:
• S (B1, B2, …, Bn )(R) changes both:
• the relation name to S, and
• the column (attribute) names to B1, B1, …..Bn
• S(R) changes:
• the relation name only to S
• (B1, B2, …, Bn )(R) changes:
• the column (attribute) names only to B1, B1, …..Bn
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 77
• For convenience, we also use a shorthand for renaming attributes in
an intermediate relation:
• If we write:
• RESULT FNAME, LNAME, SALARY (DEP5_EMPS)
• RESULT will have the same attribute names as DEP5_EMPS (same
attributes as EMPLOYEE)
• If we write:
• RESULT (F, M, L) FNAME, LNAME, SALARY (DEP5_EMPS)
• The 3 attributes of DEP5_EMPS are renamed to F, M, L respectively
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 78
Example Query
• Need to get firstname, last name and salary of employees working for department 5 and
rename attributes as first_name, last_name and salary
• RFNAME, LNAME, SALARY(DNO=5(EMPLOYEE))
• (first_name,last_name,salary) (R)
• As a shorthand
• RESULT(first_name,last_name,salary) (FNAME, LNAME, SALARY(DNO=5(EMPLOYEE)))
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 79
Example of applying multiple operations and RENAME
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 80
Relational Algebra Operations from Set Theory: UNION
• UNION Operation
• Binary operation, denoted by
• The result of R S, is a relation that includes all tuples that are either in R or
in S or in both R and S
• Duplicate tuples are eliminated
• The two operand relations R and S must be “type compatible” (or UNION
compatible)
• R and S must have same number of attributes
• Each pair of corresponding attributes must be type compatible (have same or
compatible domains)
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 81
Example
• To retrieve the social security numbers of all employees who either work in
department 5 (RESULT1 below) or directly supervise an employee who works in
department 5 (RESULT2 below)
• We can use the UNION operation as follows:
DEP5_EMPS DNO=5 (EMPLOYEE)
RESULT1 SSN(DEP5_EMPS)
RESULT2(SSN) SUPERSSN(DEP5_EMPS)
RESULT RESULT1 RESULT2
• The union operation produces the tuples that are in either RESULT1 or RESULT2 or
both
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 82
Union Example
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 83
Relational Algebra Operations from
Set Theory
• Type Compatibility of operands is required for the binary set operation UNION ,
(also for INTERSECTION , and SET DIFFERENCE –, see next slides)
• R1(A1, A2, ..., An) and R2(B1, B2, ..., Bn) are type compatible if:
• they have the same number of attributes, and
• the domains of corresponding attributes are type compatible (i.e. dom(Ai)=dom(Bi)
for i=1, 2, ..., n).
• The resulting relation for R1R2 (also for R1R2, or R1–R2, see next slides) has
the same attribute names as the first operand relation R1 (by convention)
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 84
Relational Algebra Operations from Set Theory:
INTERSECTION
• INTERSECTION is denoted by
• The result of the operation R S, is a relation that includes all tuples that are in
both R and S
• The attribute names in the result will be the same as the attribute names in R
• The two operand relations R and S must be “type compatible”
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 85
Relational Algebra Operations from Set Theory: SET
DIFFERENCE (cont.)
• SET DIFFERENCE (also called MINUS or EXCEPT) is denoted by –
• The result of R – S, is a relation that includes all tuples that are in R but not in S
• The attribute names in the result will be the same as the attribute names in R
• The two operand relations R and S must be “type compatible”
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 86
Example to illustrate the result of UNION, INTERSECT,
and DIFFERENCE
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 87
Some properties of UNION, INTERSECT, and
DIFFERENCE
• Notice that both union and intersection are commutative operations; that is
• R S = S R, and R S = S R
• Both union and intersection can be treated as n-ary operations applicable to any
number of relations as both are associative operations; that is
• R (S T) = (R S) T
• (R S) T = R (S T)
• The minus operation is not commutative; that is, in general
• R–S≠S–R
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 88
Mcq
1. Relational Algebra is a __________ query language that takes two relations as input
and produces another relation as an output of the query.
a) Relational b) Structural c) Procedural d) Fundamental
2. Which of the following is used to denote the selection operation in relational algebra?
a) Pi (Greek) b) Sigma (Greek) c) Lambda (Greek) d) Omega (Greek)
3. For select operation the ________ appear in the subscript and the ___________
argument appears in the paranthesis after the sigma.
a) Predicates, relation
b) Relation, Predicates
c) Operation, Predicates
d) Relation, Operation
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 89
4. The ___________ operation, denoted by −, allows us to find tuples that are in one
relation but are not in another.
a) Union b) Set-difference c) Difference d) Intersection
5. The operation of a relation X, produces Y, such that Y contains only selected attributes of
X. Such an operation is :
A Projection B Intersection C Union D Difference
6. Which of the following is not valid unary operation in the relational algebra ?
A select B min C project D rename
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 90
Binary relation operation-Cartesian Product
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 91
Example
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 92
Properties
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 93
CROSS PRODUCT
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 94
Modify Query
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 95
Approved by AICTE |Affiliated to VTU | Recognized by UGC with 2(f) & 12(B) status |Accredited by NBA and NAAC 96