Rdbms Unit IV
Rdbms Unit IV
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:
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
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
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
The table structure for the above ER diagram can be summarized as below.,
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:
Example: