0% found this document useful (0 votes)
44 views

Rdbms Unit IV

Rdbms

Uploaded by

bowb1043
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)
44 views

Rdbms Unit IV

Rdbms

Uploaded by

bowb1043
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/ 18

III B. Sc.

, CS Semester V RDBMS (22UCSCC54) – Unit 4

RELATIONAL LANGUAGES
SQL (Structured Query Language) is used to perform operations on the
records stored in the database, such as updating records, inserting records, deleting
records, creating and modifying database tables, views, etc. SQL is not a database
system, but it is a query language.
TUPLE RELATIONAL CALCULUS & DOMAIN RELATIONAL CALCULUS
 Relational calculus is a non-procedural query language. In the non-procedural
query language, the user is concerned with the details of how to obtain the end
results.
 The relational calculus tells what to do but never explains how to do.
Types of Relational calculus:

1. Tuple Relational Calculus (TRC)


 The tuple relational calculus is specified to select the tuples in a relation. In
TRC, filtering variable uses the tuples of a relation.
 The result of the relation can have one or more tuples.
Notation:
III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4

Where
T is the resulting tuples
P(T) is the condition used to fetch T.
Example:
{ T.name | Author(T) AND T.article = 'database' }
OUTPUT: This query selects the tuples from the AUTHOR relation. It returns a
tuple with 'name' from Author who has written an article on 'database'.
TRC (tuple relation calculus) can be quantified. In TRC, we can use Existential (∃)
and Universal Quantifiers (∀).
Example:
{ R| ∃T ∈ Authors(T.article='database' AND R.name=T.name)}
Output: This query will yield the same result as the previous one.
2. Domain Relational Calculus (DRC)
 The second form of relation is known as Domain relational calculus. In
domain relational calculus, filtering variable uses the domain of attributes.
 Domain relational calculus uses the same operators as tuple calculus. It uses
logical connectives ∧ (and), ∨ (or) and ┓ (not).
 It uses Existential (∃) and Universal Quantifiers (∀) to bind the variable.
Notation:

Where
a1, a2 are attributes
P stands for formula built by inner attributes
Example:
{< article, page, subject >| ∈javatpoint∧ subject = 'database'}
Output: This query will yield the article, page, and subject from the relational
javatpoint, where the subject is a database.
III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4

Difference between Tuple & Domain Relational Calculus:-


TUPLE RELATIONAL CALCULUS DOMAIN RELATIONAL CALCULUS
The variables represent the tuples from The variables represent the value drawn
specified relation. from specified domain.
A tuple is a single element of relation. In A domain is equivalent to column data
database term, it is a row. type and any constraints on value of
data.
In this filtering variable uses tuple of In this filtering is done based on the
relation. domain of attributes.
Query cannot be expressed using a Query can be expressed using a
membership condition. membership condition.
The QUEL or Query Language is a The QBE or Query-By-Example is query
query language related to it, language related to it.
It reflects traditional pre-relational file It is more similar to logic as a modelling
structures. language.
Notation : Notation :
{T | P (T)} or {T | Condition (T)} { a1, a2, a3, …, an | P (a1, a2, a3, …,
an)}
Example : Example :
{T | EMPLOYEE (T) AND { | < EMPLOYEE > DEPT_ID = 10 }
T.DEPT_ID = 10}
III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4

ENTITY RELATIONSHIP MODEL


Entity Relationship Model (ER Modeling) is a graphical approach to database
design. It is a high-level data model that defines data elements and their relationship
for a specified software system. An ER model is used to represent real-world objects.
An Entity is a thing or object in real world that is distinguishable from
surrounding environment. For example, each employee of an organization is a
separate entity. Following are some of major characteristics of entities.
An entity has a set of properties.
Entity properties can have values.
ER model benefits
 Provide a clear picture of the scope of information requirement
 Provides an easily understandable pictorial map for database design
 It offers an effective Framework for integrating multiple applications.

Example:
Suppose we design a school database. In this database, the student will be an
entity with attributes like address, name, id, age, etc. The address can be another
entity with attributes like city, street name, pin code,
etc and there will be a relationship between them.
III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4

Components of ER Diagram:

1. Entity:
An entity may be any object, class, person or place. In the ER diagram, an
entity can be represented as rectangles.
Consider an organization as an example- manager, product, employee,
department etc. can be taken as an entity.

Weak Entity: An entity that depends on another entity called a weak entity. The
weak entity doesn't contain any key attribute of its own. The weak entity is
represented by a double rectangle.
III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4

2. Attribute
The attribute is used to describe the property of an entity. Eclipse is used to
represent an attribute. For example, id, age, contact number, name, etc. can be
attributes of a student.

Key Attribute: The key attribute is used to represent the main characteristics of an
entity. It represents a primary key. The key attribute is represented by an ellipse with
the text underlined.
III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4

Composite Attribute: An attribute that composed of many other attributes is known


as a composite attribute. The composite attribute is represented by an ellipse, and
those ellipses are connected with an ellipse.

Multivalued Attribute: An attribute can have more than one value. These attributes
are known as a multivalued attribute. The double oval is used to represent
multivalued attribute. For example, a student can have more than one phone
number.
III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4

Derived Attribute: An attribute that can be derived from other attribute is known as a
derived attribute. It can be represented by a dashed ellipse. For example, A person's
age changes over time and can be derived from another attribute like Date of birth.

3. Relationship
A relationship is used to describe the relation between entities. Diamond or rhombus
is used to represent the relationship.

One-to-One Relationship: When only one instance of an entity is associated with the
relationship, then it is known as one to one relationship. For example, A female can
marry to one male, and a male can marry to one female.

One-to-many relationship: When only one instance of the entity on the left, and
more than one instance of an entity on the right associates with the relationship then
III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4
this is known as a one-to-many relationship. For example, Scientist can invent many
inventions, but the invention is done by the only specific scientist.

Many-to-one relationship: When more than one instance of the entity on the left, and
only one instance of an entity on the right associates with the relationship then it is
known as a many-to-one relationship. For example, Student enrolls for only one
course, but a course can have many students.

Many-to-many relationship: When more than one instance of the entity on the left,
and more than one instance of an entity on the right associates with the relationship
then it is known as a many-to-many relationship. For example, Employee can assign
by many projects and project can have many employees.
III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4

ER- Diagram Notations


ER- Diagram is a visual representation of data that describe how data is
related to each other.
Diagram Meaning
Rectangles This symbol represent entity types
Ellipses This symbol represent attributes
Diamonds This symbol represents relationship types
Lines This symbol links attributes to entity types and entity types with
other relationship types
Double Ellipses This symbol represent multi-valued attributes
Rhombus This symbol represents Relationship
Double Rhombus This symbol represents the Weak Relationship
III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4

REDUCTION TO RELATIONAL SCHEMA


A relational schema is a blueprint used in database design to represent the data
to be entered into the database and describe how that data is structured in tables
(called relations in relational schemas). The schema describes how those tables relate
to each other.
In the relational schema, the table, or relation, consists of a set of named, but
unsorted, columns (called attributes in relational schemas) and an undefined number
of unnamed and unsorted rows (called tuples in relational schemas). Each row is
unique, but the rows can be moved around as needed and stored in any order,
modified, or deleted without impacting the efficient operation of the database.
Reduction of ER diagram to Table
 Entity type becomes a table.
 All single-valued attribute becomes a column for the table.
 A key attribute of the entity type represented by the primary key.
 The multivalued attribute is represented by a separate table.
 Composite attribute represented by components.
 Derived attributes are not considered in the table.
Example:
III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4

The table structure for the above ER diagram can be summarized as below.,

Entity type becomes a table.In the given ER diagram, STUDENT forms an


individual table.
All single-valued attribute becomes a column for the table.In the STUDENT entity,
STUDENT_NAME and STUDENT_ID form the column of STUDENT table.
A key attribute of the entity type represented by the primary key.In the given ER
diagram, STUDENT_ID is the key attribute of the entity.
The multivalued attribute is represented by a separate table. In the student table, a
hobby is a multivalued attribute. So it is not possible to represent multiple values in a
single column of STUDENT table. Hence we create a table STUD_HOBBY with
III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4
column name STUDENT_ID and HOBBY. Using both the column, we create a
composite key.
Composite attribute represented by components. In the given ER diagram, student
address is a composite attribute. It contains CITY, PIN, DOOR#, STREET, and
STATE. In the STUDENT table, these attributes can merge as an individual
column.

Derived attributes are not considered in the table. In the STUDENT table, Age is the
derived attribute. It can be calculated at any point of time by calculating the
difference between current date and Date of Birth.
Example 2:

In the above ER Diagram, there are 4 entities – STUDENT, COURSE,


LECTURER & SUBJECTS  means 4 different tables
III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4
In the STUDENT table, HOBBY is a multi-valued attribute so we create it as a
separate table with STUDENT_ID
The above ER Diagram, while reducing to relational schema will be.,

ENTITY-RELATIONSHIP DESIGN ISSUES


Users often mislead the concept of the elements and the design process of the
ER diagram. Thus, it leads to a complex structure of the ER diagram and certain
issues that does not meet the characteristics of the real-world enterprise model.Here
are the some basic design issues of an ER database schema:
III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4
Use of Entity Set vsAttributes
The use of an entity set or attribute depends on the structure of the real-world
enterprise that is being modelled and the semantics associated with its attributes. It
leads to a mistake when the user use the primary key of an entity set as an attribute
of another entity set. Instead, he should use the relationship to do so. Also, the
primary key attributes are implicit in the relationship set, but we designate it in the
relationship sets.

Use of Entity Set vs. Relationship Sets


It is difficult to examine if an object can be best expressed by an entity set or
relationship set. To understand and determine the right use, the user need to
designate a relationship set for describing an action that occurs in-between the
entities. If there is a requirement of representing the object as a relationship set, then
its better not to mix it with the entity set.
Use of Binary vs n-ary Relationship Sets
Generally, the relationships described in the databases are binary
relationships. However, non-binary relationships can be represented by several
binary relationships. For example, we can create and represent a ternary relationship
'parent' that may relate to a child, his father, as well as his mother. Such relationship
can also be represented by two binary relationships i.e, mother and father, that may
relate to their child. Thus, it is possible to represent a non-binary relationship by a set
of distinct binary relationships.
Placing Relationship Attributes
The cardinality ratios can become an affective measure in the placement of the
relationship attributes. So, it is better to associate the attributes of one-to-one or one-
to-many relationship sets with any participating entity sets, instead of any
relationship set. The decision of placing the specified attribute as a relationship or
III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4
entity attribute should possess the characteristics of the real world enterprise that is
being modelled.
EXTENDED E-R FEATURES
ER diagram stands for Entity Relationship diagram. When we draw the
relationships between entities using a diagram, then it is called an entity relationship
diagram. The ER diagram is just for understanding the purpose of the database
administrator. We cannot use the ER diagram directly on the computer. ER
diagrams are converted into the tabular form then they are inserted into the computer
using any query language. In ER diagrams, we use attributes, entities, and the
relationships between entities. We use an oval shape to represent the entity and a
diamond shape to represent the relationships between entities.
The requirements and complexity of complicated databases are represented
using enhanced entity-relationship diagrams or extended entity-relationship diagram,
which are sophisticated database diagrams very similar to standard ER diagrams.
 Subclasses and Superclasses
 Specialization and Generalization
 Category or Union type
 Attribute and relationship inheritance
Superclass and Subclass: A superclass is a high-level entity that can be further
segmented into subclasses or subsets. It is also referred to as a Parent class. A
subclass can be referred to as a child or derived class.
Example: Science is a Super class which has subclasses like Physics, Chemistry,
Biology.
Generalization and Specialization: These are very common relationships found in
real entities. However, this kind of relationship was added later as an enhanced
extension to the classical ER model. Specialized classes are often called subclass
while a generalized class is called a superclass, probably inspired by object-oriented
programming. A sub-class is best understood by “IS-A analysis”. Ex:“Technician IS-
A Employee”, and “Laptop IS-A Computer”.
III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4
Union Types: EER model allows for the creation of a union type, which is a
combination of two or more entity types. The union type can have attributes and
relationships that are common to all the entity types that make up the union.

Example:

The Extended ER diagram will be.,


III B. Sc., CS Semester V RDBMS (22UCSCC54) – Unit 4

You might also like