2 - Relational Model
2 - Relational Model
Model
28-Apr-25 Dept. of I&CT 1
Data Model
• Data Model is a collection of concepts that can be
used to describe the structure of a database
• Structure of a database:
• Data types,
• Relationships, and
• Constraints that apply to the data
2. Low-level or physical or internal data models provide concepts that describe the
details of how data is stored on the computer storage media, typically magnetic
disks
- Not for end users but for specialists
- Program-data independence.
- Support of multiple views of the data
• Three levels:
1. Internal level has an internal schema that describes
the physical storage structure of the database.
- Uses a physical data model and describes the
complete details of data
28-Apr-25 Dept. ofstorage
I&CT and access paths for
10
Three - Schema Architecture
1. Internal level : internal schema that describes the
physical storage structure of the database.
• Uses a physical data model and describes the complete details of data
storage and access paths for the database.
• The attribute values of a tuple must be such that they can uniquely identify
the tuple i.e., no two tuples in a relation are allowed to have exactly the
same value for all attributes.
• Two distinct tuples in any state of the relation cannot have identical
values for (all) the attributes in the key.
• Any superkey formed from a single attribute is also a key whereas a key with
multiple attributes must require all its attributes together to have the
uniqueness
28-Apr-25 property. Dept. of I&CT 17
Keys
• There is a possibility of having more than one
candidate key for a relation
• Term primary key is used to denote the chosen
candidate key
• Primary key attributes are also underlined
• Other candidate keys are designated as unique keys
28-Apr-25 branch_name=“Manipal”(account)
Dept. of I&CT 31
Project Operation – Example
• Relation r: A B C
10 1
20 1
30 1
40 2
A,C (r)
A C A C
1 1
1 = 1
1 2
2
28-Apr-25 Dept. of I&CT 32
Project Operation
• Notation
A1 , A2 ,, Ak (r )
where A1, A2 are attribute names and r is a
relation name.
• 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
A B
r s:
1
2
1
3
28-Apr-25 Dept. of I&CT 35
Set Difference Operation
• Notation r – s
• Defined as:
r – s = {t | t r and t s}
A B
r – s: 1
1
1
10 a
2 10 a
20 b 1 10 a
10 b 1 10 a
r 1 20 b
1 10 b
2 10 a
s 2 10 a
2 20 b
2 10 b
A B C D E
10 a
• A=C(r x s)
1
10 a
2
2 20 b
28-Apr-25 Dept. of I&CT 40
Rename Operation
• Allows us to name, and therefore to refer to, the results
of relational - algebra expressions.
• Allows us to refer to a relation by more than one name.
• Example: x (E)
returns the expression E under the name X
• If a relational-algebra expression E has arity n, then
x ( A ,A ,...,A ) (E )
returns the result of expression E under the name X, and
1 2 n
with the
attributes renamed to A , A2 , …., An . 1
1
2
2
3
1
r s
•r s
A B
2
B D E
A B C D A B C D E
1 a 1 a 1 a
2 a 3 a 1 a
4 b 1 a 1 a
1 a 2 b 1 a
2 b 3 b 2 b
r s
• Find the loan number for each loan of an amount greater than $1200
• Find the names of all customers who have a loan and an account at bank.
Query 2
customer_name(loan.loan_number = borrower.loan_number (
(branch_name = “Manipal” (loan)) x borrower))
balance(account) - account.balance
(account.balance < d.balance (account x
d (account)))