Unit 2
Unit 2
Unit 2
Language
• Relational Data Model Concepts,
• Integrity Constraints, Entity Integrity, Referential Integrity, Keys
Constraints, Domain Constraints, Relational Algebra, Relational
Calculus, Tuple and Domain Calculus.
• Introduction on SQL: Characteristics of SQL, Advantage of SQL.
SQl Data Type and Literals.
• Types of SQL Commands.
• SQL Operators and Their Procedure. Tables, Views and Indexes.
• Queries and Sub Queries. Aggregate Functions.
• Insert, Update and Delete Operations, Joins, Unions,
Intersection, Minus, Cursors, Triggers, Procedures in SQL/PL SQL.
HISTORY-
• First introduced by Ted Codd(in 1970).
• Uses the concept of mathematical relation (set theory).
• First commercial implementations of relational model-
Oracle DBMS, SQL/DS system(IBM)
• Current popular RDMSs – SQL Server & Access (Microsoft) DB2 & Infomix (IBM).
• Standard for commercial RDBMS – SQL Query.
Relation Name
STUDENT
Roll. Name Age Phone City
No
Tuples
1 David 24 8654625868 Noida
2 John 25 9465356546 Delhi
1 HARRY 19
2 BEN 22
Cardinality = 3
3 KATHY 21
• Selection(σ)
• Projection(∏)
• Union(∪)
• Set Difference(-)
• Rename
• Cartesian Product(X)
• Select (σ)
• Select operation is done by Selection Operator which is represented
by "sigma"(σ).
• It is used to retrieve tuples(rows) from the table where the given condition is
satisfied.
• is a unary operator means it requires only one operand.
Notation : σ p(R)
Where σ is used to represent SELECTION
R is used to represent RELATION
p is the logic formula
• Project (∏)
• Project operation is done by Projection Operator which is represented by "pi"(∏).
• It is used to retrieve certain attributes(columns) from the table.
• It is also known as vertical partitioning as it separates the table vertically.
• It is also a unary operator.
• Notation : ∏ a(r)
Where ∏ is used to represent PROJECTION
r is used to represent RELATION
a is the attribute list
NAME
Aman
Atul
Baljeet
Harsh
Prateek
∏ ROLL,NAME(STUDENT)
• Union (∪)
• Union operation is done by Union Operator which is represented by "union"(∪).
• It is the same as the union operator from set theory, i.e., it selects all tuples from
both relations but with the exception that for the union of two relations/tables
both relations must have the same set of Attributes.
• It is a binary operator as it requires two operands.
Notation: R ∪ S
• Where R is the first relation
S is the second relation
∏ NAME(STUDENT) ∪ ∏ NAME(EMPLOYEE)
NAME
Aman
Anant
Ashish
Atul
Baljeet
Harsh
Pranav
Prateek
As we can see from the above output it also eliminates duplicates.
19/12/2023 Faculty Name Unit -2 24
Types of Relational operation(cont…)
• Set Difference (-)
• Set Difference as its name indicates is the difference
between two relations (R-S).
• It is denoted by a "Hyphen"(-) and it returns all the
tuples(rows) which are in relation R but not in
relation S. It is also a binary operator.
• Notation : R – S
• Where R is the first relation
• S is the second relation
• Just like union, the set difference also comes with the
exception of the same set of attributes in both
relations.
Types of Relational operation(cont…)
• Let's take an example where we would like to know the names of students who are
in STUDENT Relation but not in EMPLOYEE Relation.
∏ NAME(STUDENT) - ∏ NAME(EMPLOYEE)
NAME
Aman
Atul
Prateek
EMPLOYEE
ROLL NAME AGE NAME AGE
_NO
1 Aman 20 E-1 Anant 20
1 Aman 20 E-2 Ashish 23
1 Aman 20 E-3 Baljeet 25
1 Aman 20 E-4 Harsh 20
1 Aman 20 E-5 Pranav 22
2 Atul 18 E-1 Anant 20
2 Atul 18 E-2 Ashish 23
2 Atul 18 E-3 Baljeet 25
2 Atul 18 E-4 Harsh 20
2 Atul 18 E-5 Pranav 22
. . . And so on.
19/12/2023 Faculty Name Unit -2 28
Types of Relational operation(cont…)
• Rename (ρ)
• Rename operation is denoted by "Rho"(ρ).
• As its name suggests it is used to rename the output relation.
• Rename operator too is a binary operator.
Notation: ρ(R,S)
• Where R is the new relation name
• S is the old relation name
• Let's have an example to clarify this
ρ(STUDENT_NAME,∏ NAME(STUDENT))
STUDENT_NAME
NAME
Aman
Atul
Baljeet
Harsh
Prateek
• Derived Operations
• Also known as extended operations, these operations can be derived from basic
operations and hence named Derived Operations.
• These include three operations:
• Join Operations,
• Intersection operations, and
• Division operations.
• Let's study them one by one.