0% found this document useful (0 votes)
23 views44 pages

Understanding the Relational Data Model

The document outlines the relational data model proposed by E.F. Codd, detailing its structure, advantages, disadvantages, and key concepts such as keys, integrity constraints, and query languages. It explains the representation of data in tables, the significance of attributes, and various types of keys including primary, foreign, and composite keys. Additionally, it covers relational algebra and calculus as procedural and non-procedural query languages for database interaction.

Uploaded by

razafaisalr087
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views44 pages

Understanding the Relational Data Model

The document outlines the relational data model proposed by E.F. Codd, detailing its structure, advantages, disadvantages, and key concepts such as keys, integrity constraints, and query languages. It explains the representation of data in tables, the significance of attributes, and various types of keys including primary, foreign, and composite keys. Additionally, it covers relational algebra and calculus as procedural and non-procedural query languages for database interaction.

Uploaded by

razafaisalr087
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Relational Data Model

• E.F. Codd proposed the relational Model to model data in the


form of relations or tables. After designing the conceptual
model of the Database using ER diagram, we need to convert
the conceptual model into a relational model which can be
implemented using any RDBMS language like Oracle SQL,
MySQL
• The relational model represents how data is stored in
Relational Databases. A relational database consists of a
collection of tables, each of which is assigned a unique name.
Consider a relation STUDENT with attributes ROLL_NO, NAME,
ADDRESS, PHONE, and AGE
• Relational model can represent as a table with columns and
rows. Each row is known as a tuple. Each table of the column
has a name or attribute.
Domain: It contains a set of atomic values that an attribute
can take.
Attribute: It contains the name of a column in a particular
table. Each attribute Ai must have a domain, dom(Ai)
Relational instance: In the relational database system, the
relational instance is represented by a finite set of tuples.
Relation instances do not have duplicate tuples.
Relational schema: A relational schema contains the name
of the relation and name of all columns or attributes.
Relational key: In the relational key, each row has one or
more attributes. It can identify the row in the relation
uniquely.
Degree: The number of attributes in the relation is known as the
degree of the relation. The STUDENT relation defined above has
degree 5.
Cardinality: The number of tuples in a relation is known as
cardinality. The STUDENT relation defined above has cardinality
4.
NULL Values: The value which is not known or unavailable is
called a NULL value. It is represented by blank space.
Example: STUDENT Relation

NAME ROLL_NO PHONE_NO ADDRESS AGE


Ram 14795 7305758992 Noida 24
Shyam 12839 9026288936 Delhi 35
Laxman 33289 8583287182 Gurugram 20
Mahesh 27857 7086819134 Ghaziabad 27
Ganesh 17282 9028 9i3988 Delhi 40

In the given table, NAME, ROLL_NO, PHONE_NO, ADDRESS, and AGE are the attributes.
The instance of schema STUDENT has 5 tuples.
• Name of the relation is distinct from all other
relations.
• Each relation cell contains exactly one atomic
(single) value
• Each attribute contains a distinct name
• Attribute domain has no significance
• tuple has no duplicate value
• Order of tuple can have a different sequence
Advantages of the Relational Model
• Simple model: Relational Model is simple and easy to use
in comparison to other languages.
• Flexible: Relational Model is more flexible than any other
relational model present.
• Secure: Relational Model is more secure than any other
relational model.
• Data Accuracy: Data is more accurate in the relational
data model.
• Data Integrity: The integrity of the data is maintained in
the relational model.
• Operations can be Applied Easily: It is better to perform
operations in the relational model.
Disadvantages of the Relational Model
Relational Database Model is not very good for large databases.
Sometimes, it becomes difficult to find the relation between tables.
Because of the complex structure, the response time for queries is high

Characteristics of the Relational Model


Data is represented in rows and columns called relations.
Data is stored in tables having relationships between them called the
Relational model.
The relational model supports the operations like Data definition, Data
manipulation, and Transaction management.
Each column has a distinct name and they are representing attributes.
Each row represents a single entity.
Keys
• Keys are one of the basic requirements of a relational
database model. It is widely used to identify the
tuples(rows) uniquely in the table. We also use keys
to set up relations amongst various columns and
tables of a relational database.
Different Types of Keys
Candidate Key
The minimal set of attributes that can uniquely identify a tuple is known
as a candidate key. For Example, STUD_NO in STUDENT relation.
• Except for the primary key, the remaining attributes are considered a
candidate key. The candidate keys are as strong as the primary key.
• It is a minimal super key.
• It is a super key with no repeated data is called a candidate key.
• The minimal set of attributes that can uniquely identify a record.
• It must contain unique values.
• It can contain NULL values.
• Every table must have at least a single candidate key.
• A table can have multiple candidate keys but only one primary key.
• The value of the Candidate Key is unique and may be null for a tuple.
• There can be more than one candidate key in a relationship.
For example: In the EMPLOYEE table, id is best suited for
the primary key. The rest of the attributes, like SSN,
Passport_Number, License_Number, etc., are considered
a candidate key.
Primary Key
There can be more than one candidate key in relation out of
which one can be chosen as the primary key. For Example,
STUD_NO, as well as STUD_PHONE, are candidate keys for
relation STUDENT but STUD_NO can be chosen as the primary
key
• It is a unique key.
• It can identify only one tuple (a record) at a time.
• It has no duplicate values, it has unique values.
• It cannot be NULL.
• Primary keys are not necessarily to be a single column;
more than one column can also be a primary key for a table.
Super Key
Super key is an attribute set that can uniquely identify a tuple. A
super key is a superset of a candidate key.
• Adding zero or more attributes to the candidate key generates
the super key.
• A candidate key is a super key but vice versa is not true.
• Super Key values may also be NULL.
Foreign key
• Foreign keys are the column of the table used to point
to the primary key of another table.
• Every employee works in a specific department in a
company, and employee and department are two
different entities. So we can't store the department's
information in the employee table. That's why we link
these two tables through the primary key of one table.
• We add the primary key of the DEPARTMENT table,
Department_Id, as a new attribute in the EMPLOYEE
table.
• In the EMPLOYEE table, Department_Id is the foreign
key, and both the tables are related.
Alternate key
• There may be one or more attributes or a combination
of attributes that uniquely identify each tuple in a
relation. These attributes or combinations of the
attributes are called the candidate keys. One key is
chosen as the primary key from these candidate keys,
and the remaining candidate key, if it exists, is termed
the alternate key. In other words, the total number of
the alternate keys is the total number of candidate keys
minus the primary key. The alternate key may or may
not exist. If there is only one candidate key in a relation,
it does not have an alternate key.
For example, employee relation has two
attributes, Employee_Id and PAN_No, that act as
candidate keys. In this relation, Employee_Id is
chosen as the primary key, so the other
candidate key, PAN_No, acts as the Alternate
key.
Composite key
Whenever a primary key consists of more than one attribute, it is
known as a composite key. This key is also known as Concatenated
Key.
Sometimes, a table might not have a single column/attribute that
uniquely identifies all the records of a table. To uniquely identify
rows of a table, a combination of two or more columns/attributes
can be used. It still can give duplicate values in rare cases. So, we
need to find the optimal set of attributes that can uniquely identify
rows in a table.
• It acts as a primary key if there is no primary key in a table
• Two or more attributes are used together to make a composite
key.
• Different combinations of attributes may give different accuracy
in terms of identifying the rows uniquely.
Integrity Constraints
• Integrity constraints are a set of rules. It is
used to maintain the quality of information.
• Integrity constraints ensure that the data
insertion, updating, and other processes have
to be performed in such a way that data
integrity is not affected.
• Thus, integrity constraint is used to guard
against accidental damage to the database.
Types of Integrity Constraint
Domain constraints
• Domain constraints can be defined as the definition of a
valid set of values for an attribute.
• The data type of domain includes string, character,
integer, time, date, currency, etc. The value of the
attribute must be available in the corresponding domain.
Entity integrity constraints
• The entity integrity constraint states that primary key value can't be
null.
• This is because the primary key value is used to identify individual
rows in relation and if the primary key has a null value, then we
can't identify those rows.
• A table can contain a null value other than the primary key field.
Referential Integrity Constraints
• A referential integrity constraint is specified between two tables.
• In the Referential integrity constraints, if a foreign key in Table 1 refers to
the Primary Key of Table 2, then every value of the Foreign Key in Table 1
must be null or be available in Table 2.
Key constraints
• Keys are the entity set that is used to identify an entity within its
entity set uniquely.
• An entity set can have multiple keys, but out of which one key will
be the primary key. A primary key can contain a unique and null
value in the relational table.
Relational Query Language
• Relational Database systems are expected to be equipped
with a query language that assists users to query the
database.
• Relational Query Language is used by the user to
communicate with the database user requests for the
information from the database.
• Relational algebra breaks the user requests and instructs
the DBMS to execute the requests. It is the language by
which the user communicates with the database. They are
generally on a higher level than any other programming
language. These relational query languages can be
Procedural and Non-Procedural.
Types of Relational Query Language
There are two types of relational query
language:
• Procedural Query Language
• Non-Procedural Language
Procedural Query Language
In Procedural Language, the user instructs the
system to perform a series of operations on the
database to produce the desired results. Users
tell what data to be retrieved from the database
and how to retrieve it. Procedural Query
Language performs a set of queries instructing
the DBMS to perform various transactions in
sequence to meet user requests.
Structure Query language (SQL) is based on
relational algebra.
Relational Algebra is a Procedural Query Language

• There are a few operators that are used in relational algebra –


• Select (sigma): Returns rows of the input relation that satisfy the
provided predicate. It is unary Operator means requires only one
operand.
• Projection (ℼ): Show the list of those attribute which we desire to
appear and rest other attributes are eliminated from the table. It
seperates the table vertically.
• Set Difference (-): It returns the difference between two relations . If we
have two relations R and S them R-S will return all the tuples (row)
which are in relation R but not in Relation S , It is binary operator.
• Cartesian Product (X): Combines every tuple (row) of one table with
every tuple (row) in other table ,also referred as cross Product . It is a
binary operator.
• Union (U): Outputs the union of tuples from both the relations.
Duplicate tuples are eliminated automatically. It is a binary operator
means it require two operands.
Non-Procedural Language
In Non Procedural Language user outlines the
desired information without giving a specific
procedure or without telling the steps by step
process for attaining the information. It only
gives a single Query on one or more tables to
get .The user tells what is to be retrieved from
the database but does not tell how to
accomplish it.
Relational calculus is a Non Procedural Language .

• Relational Calculus exists in two forms:


• Tuple Relational Calculus (TRC): is a non
procedural query language , It is used for
selecting the tuples that satisfy the given
condition or predicate . The result of the
relation can have one or more tuples (row).
• Domain Relational Calculus (DRC): is a Non
Procedural Query Language , the records are
filtered based on the domains , DRC uses the list
of attributes to be selected from relational
based on the condition.
Relational Algebra
• Relational algebra is a procedural query
language. It gives a step by step process to
obtain the result of the query. It uses
operators to perform queries.
• Relational algebra mainly provides a
theoretical foundation for relational databases
• The main purpose of using Relational Algebra
is to define operators that transform one or
more input relations into an output relation.
Types of Relational operation
1. Selection(σ):-The select operation selects tuples
that satisfy a given predicate.
• It is denoted by sigma (σ).
SYNTAX: σ p(r)
Where:
σ is used for selection prediction
r is used for relation
p is used as a propositional logic formula which may
use connectors like: AND OR and NOT. These
relational can use as relational operators like =, ≠, ≥, <,
>, ≤.
The selection operator only selects the required tuples but does not
display them. For display, the data projection operator is used.
2. Project Operation (∏ ):This operation shows
the list of those attributes that we wish to
appear in the result. Rest of the attributes are
eliminated from the table.
• It is denoted by ∏.
SYNTAX : ∏ A1, A2, An (r)
Where
A1, A2, A3 is used as an attribute name of
relation r.
Union Operation (U) :Suppose there are two tuples
R and S. The union operation contains all the tuples
that are either in R or S or both in R & S.
• It eliminates the duplicate tuples. It is denoted by
∪.
SYNTAX : R ∪ S
A union operation must hold the following condition:
• R and S must have the attribute of the same
number.
• Duplicate tuples are eliminated automatically.
The only constraint in the union of two relations is that both relations
must have the same set of Attributes.
Set Intersection(∩):- Suppose there are two
tuples R and S. The set intersection operation
contains all tuples that are in both R & S.
• It is denoted by intersection ∩.
SYNTAX : R ∩ S
The only constraint in the Set Difference between two relations is
that both relations must have the same set of Attributes.
Set Difference(-):Suppose there are two tuples R
and S. The set intersection operation contains all
tuples that are in R but not in S.
• It is denoted by intersection minus (-).
SYNTAX : R - S
• The only constraint in the Set Difference between two relations is
that both relations must have the same set of Attributes.
• Cartesian product:- The Cartesian product is
used to combine each row in one table with
each row in the other table. It is also known as
a cross product.
• It is denoted by X.
Notation: E X D
Cross Product(X): Cross-product between two
relations. Let’s say A and B, so the cross product
between A X B will result in all the attributes of
A followed by each attribute of B. Each record of
A will pair with every record of B.
Rename Operation:
• The rename operation is used to rename the
output relation. It is denoted by rho (ρ).
• Example: We can use the rename operator to
rename STUDENT relation to STUDENT1.
• ρ(STUDENT1, STUDENT)
Join Operations
• A Join operation combines related tuples from
different relations, if and only if a given join
condition is satisfied.
It is denoted by ⋈
Operation: (Table1 ⋈ Table2)

You might also like