0% found this document useful (0 votes)
479 views12 pages

KMBNIT03 - Unit 2

The document discusses different data modeling concepts including the relational data model, semantic data model, keys in database management systems, integrity constraints, and relational algebra. The relational data model organizes data in tables and uses common fields to define relationships. Semantic modeling defines an inherent structure for data through classification, aggregation, and generalization abstractions.

Uploaded by

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

KMBNIT03 - Unit 2

The document discusses different data modeling concepts including the relational data model, semantic data model, keys in database management systems, integrity constraints, and relational algebra. The relational data model organizes data in tables and uses common fields to define relationships. Semantic modeling defines an inherent structure for data through classification, aggregation, and generalization abstractions.

Uploaded by

Aditya Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

KMBN IT03- Unit2

Relational Data Model, Semantic Data Model


Relational Data Model

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.

Hence, tables are also known as relations in relational model.

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.

Abstractions used in a semantic data model:

 Classification – “instance_of” relations


 Aggregation – “has_a” relations
 Generalization – “is_a” relation

DBMS Keys, Concepts of Super Key, Candidate key, Primary key


KEYS in DBMS is an attribute or set of attributes which helps you to identify a
row(tuple) in a relation(table). They allow you to find the relation between two tables.
Keys help you uniquely identify a row in a table by a combination of one or more
columns in that table. Key is also helpful for finding unique record or row from the table.
Database key is also helpful for finding unique record or row from the table.

Example:
Employee ID FirstName Surname Name

11 Sachin Tendulkar

22 Steve Smith

33 Alex Hale

Objectives:

 Allows you to establish a relationship between and identify the relation


between tables.
 Keys help you to identify any row of data in a table. In a real-world
application, a table could contain thousands of records. Moreover, the
records could be duplicated. Keys in RDBMS ensure that you can
uniquely identify a table record despite these challenges.
 Help you to enforce identity and integrity in the relationship.

Super Key:

Super key is an attribute set that can uniquely identify a tuple. A super key is a superset
of a candidate key.

For example: In the above EMPLOYEE table, for (EMPLOEE_ID, EMPLOYEE_NAME),


the name of two employees can be the same, but their EMPLYEE_ID can’t be the
same. Hence, this combination can also be a key.

The super key would be EMPLOYEE-ID (EMPLOYEE_ID, EMPLOYEE-NAME), etc.

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 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

Integrity Constraints
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

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:

2. 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.

Example:

3. 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.

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.

The fundamental operations of relational algebra are as follows:

 Select
 Project
 Union
 Set different
 Cartesian product
 Rename

We will discuss all these operations in the following sections.

Select Operation (σ)

It selects tuples that satisfy the given predicate from a relation.

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’.

σsubject = “database” and price = “450”(Books)


Output − Selects tuples from books where subject is ‘database’ and ‘price’ is 450.

σsubject = “database” and price = “450” or year > “2010”(Books)


Output − Selects tuples from books where subject is ‘database’ and ‘price’ is 450 or those books
published after 2010.
Project Operation (∏)

It projects column(s) that satisfy a given predicate.

Notation − ∏A1, A2, An (r)

Where A1, A2 , An are attribute names of relation r.

Duplicate rows are automatically eliminated, as relation is a set.

For example −

∏subject, author (Books)


Selects and projects columns named as subject and author from the relation Books.

Union Operation (∪)

It performs binary union between two given relations and is defined as −

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).

For a union operation to be valid, the following conditions must hold −

 r, and s must have the same number of attributes.


 Attribute domains must be compatible.
 Duplicate tuples are automatically eliminated.

∏ author (Books) ∪ ∏ author (Articles)


Output − Projects the names of the authors who have either written a book or an article or both.

Set Difference (−)

The result of set difference operation is tuples, which are present in one relation but are not in the
second relation.

Notation − r − s

Finds all the tuples that are present in r but not in s.


∏ author (Books) − ∏ author (Articles)
Output − Provides the name of authors who have written books but not articles.

Cartesian Product (Χ)

Combines information of two different relations into one.

Notation − r Χ s

Where r and s are relations and their output will be defined as −

r Χ s = { q t | q ∈ r and t ∈ s}

σauthor = ‘tutorialspoint’(Books Χ Articles)


Output − Yields a relation, which shows all the books and articles written by tutorialspoint.

Rename Operation (ρ)

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)

Where the result of expression E is saved with name of x.

Additional operations are −

 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.

Relational calculus exists in two forms −

Tuple Relational Calculus (TRC)

Filtering variable ranges over tuples


Notation − {T | Condition}

Returns all tuples T that satisfies a condition.

For example −

{ T.name | Author(T) AND T.article = ‘database’ }


Output − Returns tuples with ‘name’ from Author who has written article on ‘database’.

TRC can be quantified. We can use Existential (∃) and Universal Quantifiers (∀).

For example −

{ R| ∃T ∈ Authors(T.article=’database’ AND R.name=T.name)}


Output − The above query will yield the same result as the previous one.

Domain Relational Calculus (DRC)

In DRC, the filtering variable uses the domain of attributes instead of entire tuple values (as done
in TRC, mentioned above).

Notation −

{ a1, a2, a3, …, an | P (a1, a2, a3, … ,an)}

Where a1, a2 are attributes and P stands for formulae built by inner attributes.

For example −

{< article, page, subject > | ∈ TutorialsPoint ∧ subject = ‘database’}


Output − Yields Article, Page, and Subject from the relation TutorialsPoint, where subject is
database.

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.

You might also like