KMBNIT03 - Unit 2
KMBNIT03 - Unit 2
In this model, data is organised in two-dimensional tables and the relationship is maintained by
storing a common field.
This model was introduced by E.F Codd in 1970, and since then it has been the most widely used
database model, infact, we can say the only database model used around the world.
The basic structure of data in the relational model is tables. All the information related to a
particular type is stored in rows of that table.
In the coming tutorials we will learn how to design tables, normalize them to reduce data
redundancy and how to use Structured Query language to access data from tables.
Semantic Data Model
The semantic data model is a method of structuring data in order to represent it in a specific
logical way. It is a conceptual data model that includes semantic information that adds a basic
meaning to the data and the relationships that lie between them. This approach to data modeling
and data organization allows for the easy development of application programs and also for the
easy maintenance of data consistency when data is updated.
The semantic data model is a relatively new approach that is based on semantic principles that
result in a data set with inherently specified data structures. Usually, singular data or a word does
not convey any meaning to humans, but paired with a context this word inherits more meaning.
In a database environment, the context of data is often defined mainly by its structure, such as its
properties and relationships with other objects. So, in a relational approach, the vertical structure
of the data is defined by explicit referential constraints, but in semantic modeling this structure is
defined in an inherent way, which is to say that a property of the data itself may coincide with a
reference to another object.
A semantic data model may be illustrated graphically through an abstraction hierarchy diagram,
which shows data types as boxes and their relationships as lines. This is done hierarchically so
that types that reference other types are always listed above the types that they are referencing,
which makes it easier to read and understand.
Example:
Employee ID FirstName Surname Name
11 Sachin Tendulkar
22 Steve Smith
33 Alex Hale
Objectives:
Super Key:
Super key is an attribute set that can uniquely identify a tuple. A super key is a superset
of a candidate key.
Candidate 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.
Primary key:
It is the first key used to identify one and only one instance of an entity uniquely. An
entity can contain multiple keys, as we saw in the PERSON table. The key which is
most suitable from those lists becomes a primary key.
In the EMPLOYEE table, ID can be the primary key since it is unique for each
employee. In the EMPLOYEE table, we can even select License_Number and
Passport_Number as primary keys since they are also unique.
For each entity, the primary key selection is based on requirements and developers.
Integrity Constraints
Integrity Constraints
Integrity Constraints
Integrity Constraints
1. 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.
Example:
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.
Example:
Example:
4. 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.
Example:
Relational Algebra
Relational algebra is a procedural query language, which takes instances of relations as input and
yields instances of relations as output. It uses operators to perform queries. An operator can be
either unary or binary. They accept relations as their input and yield relations as their output.
Relational algebra is performed recursively on a relation and intermediate results are also
considered relations.
Select
Project
Union
Set different
Cartesian product
Rename
Notation − σp(r)
Where σ stands for selection predicate and r stands for relation. p is prepositional logic formula
which may use connectors like and, or, and not. These terms may use relational operators like −
=, ≠, ≥, < , >, ≤.
For example −
σsubject = “database”(Books)
Output − Selects tuples from books where subject is ‘database’.
For example −
r ∪ s = { t | t ∈ r or t ∈ s}
Notation − r U s
Where r and s are either database relations or relation result set (temporary relation).
The result of set difference operation is tuples, which are present in one relation but are not in the
second relation.
Notation − r − s
Notation − r Χ s
r Χ s = { q t | q ∈ r and t ∈ s}
The results of relational algebra are also relations but without any name. The rename operation
allows us to rename the output relation. ‘rename’ operation is denoted with small Greek
letter rho ρ.
Notation − ρ x (E)
Set intersection
Assignment
Natural join
Relational Calculus
In contrast to Relational Algebra, Relational Calculus is a non-procedural query language, that is,
it tells what to do but never explains how to do it.
For example −
TRC can be quantified. We can use Existential (∃) and Universal Quantifiers (∀).
For example −
In DRC, the filtering variable uses the domain of attributes instead of entire tuple values (as done
in TRC, mentioned above).
Notation −
Where a1, a2 are attributes and P stands for formulae built by inner attributes.
For example −
Just like TRC, DRC can also be written using existential and universal quantifiers. DRC also involves
relational operators.
The expression power of Tuple Relation Calculus and Domain Relation Calculus is equivalent to
Relational Algebra.