0% found this document useful (0 votes)
5 views15 pages

RDBMS - Unit 1 Notes

The document provides an overview of the Relational Model in Database Management Systems (DBMS), detailing its structure through tables (relations), rows (tuples), and columns (attributes). It explains fundamental concepts such as relational schema, keys, integrity constraints, and various operations like selection, projection, and join. Additionally, it highlights the advantages of the relational model, including simplicity, flexibility, and data integrity.

Uploaded by

rudramilke
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)
5 views15 pages

RDBMS - Unit 1 Notes

The document provides an overview of the Relational Model in Database Management Systems (DBMS), detailing its structure through tables (relations), rows (tuples), and columns (attributes). It explains fundamental concepts such as relational schema, keys, integrity constraints, and various operations like selection, projection, and join. Additionally, it highlights the advantages of the relational model, including simplicity, flexibility, and data integrity.

Uploaded by

rudramilke
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/ 15

UNIT 1 : RELATIONAL MODEL CONCEPTS

Relational Model in DBMS


The Relational Model represents data and their relationships through a collection of tables. Each
table also known as a relation consists of rows and columns. Every column has a unique name and
corresponds to a specific attribute, while each row contains a set of related data values representing
a real-world entity or relationship. This model is part of the record-based models which structure
data in fixed-format records each belonging to a particular type with a defined set of attributes.

E.F. Codd introduced the Relational Model to organize data as relations or tables. After creating
the conceptual design of a database using an ER diagram, this design must be transformed into a
relational model which can then be implemented using relational database systems like Oracle
SQL or MySQL.

What is the Relational Model?


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 shown in the table.
1. Basic Concepts:
1. Relation:

 A relation in RDBMS is basically a table.


 It consists of rows and columns.
 Each relation has a name (like a table name).

Example:
Let’s say we have a table called Student:

RollNo Name Age Dept


101 Harry 20 CSE
102 Hermione 19 ECE
103 Ron 21 CSE

Here, the Student table is a relation.

2. Tuple:

 A tuple is a row in a relation (table).


 It represents a single record or data entry.

Example:
In the Student relation above:

 (101, Harry,20, CSE) is a tuple.


 (102,Hermione,19,ECE) is another tuple.

So, each row = tuple.

3. Attribute:

 An attribute is a column in a relation (table).


 It represents a property or characteristic of a record.
 Each attribute has a name (like a column name) and a domain (the set of values it can
take).

Example:
In the Student relation:

 RollNo, Name, Age, and Dept are attributes.


 The domain of the Age attribute is all possible integers (like 18, 19, 20…).
Domain: The set of possible values for an attribute.
Degree (or arity): The number of attributes (columns) in a relation.
Cardinality: The number of tuples (rows) in a relation.
Relational Instance: It is the collection of records present in the relation at a given time.

2. Relational Schema:
A relation schema describes the structure of a relation, including its attributes and domains.
Notation: R(A1, A2, ..., An)
Example: Student(RollNo, Name, Age, Dept)

3. Keys:
Superkey: A set of one or more attributes that uniquely identifies a tuple.
Candidate key: A minimal superkey — no subset of it can uniquely identify a tuple.
Primary key: A chosen candidate key used to identify tuples uniquely.
Foreign key: An attribute in one relation that refers to the primary key of another relation —
establishes a relationship between tables.
4. Integrity Constraints:
Domain constraints: Each attribute's value must lie within a specified domain.
Key constraints: No two rows can have the same value for the primary key.
Entity integrity: Primary keys cannot be null.
Referential integrity: A foreign key must either be null or match a value in the referenced relation’s
primary key.
5. Operations:
Select (σ): Filters rows based on a condition.
Project (π): Retrieves specific columns (attributes).
Union (∪): Combines tuples from two relations (both must have the same schema).
Set difference (-): Returns tuples in one relation but not in another.
Cartesian product (×): Combines all tuples from two relations.
Join: Combines related tuples from two relations based on a condition.
6. Advantages of the Relational Model:
Simplicity: Easy-to-understand tabular structure.
Flexibility: Supports powerful query languages like SQL.
Data integrity: Ensures accuracy through constraints.
Scalability: Efficient for large datasets.

Characteristics/Features of the Relational Model


Data Representation: Data is organized in tables (relations), with rows (tuples) representing
records and columns (attributes) representing data fields.
Atomic Values: Each attribute in a table contains atomic values, meaning no multi-valued or
nested data is allowed in a single cell.
Unique Keys: Every table has a primary key to uniquely identify each record, ensuring no
duplicate rows.
Attribute Domain: Each attribute has a defined domain, specifying the valid data types and
constraints for the values it can hold.
Tuples as Rows: Rows in a table, called tuples, represent individual records or instances of real-
world entities or relationships.
Relation Schema: A table’s structure is defined by its schema, which specifies the table name,
attributes, and their domains.
Data Independence: The model ensures logical and physical data independence, allowing
changes in the database schema without affecting the application layer.
Integrity Constraints: The model enforces rules like:
Domain constraints: Attribute values must match the specified domain.
Entity integrity: No primary key can have NULL values.
Referential integrity: Foreign keys must match primary keys in the referenced table or be NULL.
Relational Operations: Supports operations like selection, projection, join, union, and
intersection, enabling powerful data retrieval manipulation.
Data Consistency: Ensures data consistency through constraints, reducing redundancy and
anomalies.
Set-Based Representation: Tables in the relational model are treated as sets, and operations
follow mathematical set theory principles.

Fundamental Operations of Relational Algebra:


1. Selection (σ):

Purpose: Filters rows (tuples) based on a condition.

Notation:

σcondition(R)
 σ is the selection operator.
 R is the relation (table).
 The condition is applied to each row.

Example:
Given the Student table:

RollNo Name Age Dept


101 Harry 20 CSE
102 Hermione 19 ECE
103 Ron 21 CSE

To get all students in CSE:

σDept=’CSE’(Student)
Result:

RollNo Name Age Dept


101 Harry 20 CSE
103 Ron 21 CSE

2. Projection (π):

Purpose: Selects specific columns (attributes) from a table.

Notation:

Π attribute1, attribute2,…(R)
 π is the projection operator.
 It produces a new relation with only the specified columns.
Example:
To get only the names and departments of students:

πName, Dept (Student)


Result:

Name Dept
Harry CSE
Hermione ECE
Ron CSE

3. Union (∪):

Purpose: Combines rows from two relations, removing duplicates.

Notation:

R S
 Works only if R and S have the same attributes (compatible schemas).

Example:
Student1:

RollNo Name
101 Harry
102 Hermione

Student2:

RollNo Name
102 Hermione
103 Ron

Student1 Student2
Result:

RollNo Name
101 Harry
RollNo Name
102 Hermione
103 Ron

4. Set Difference (−):

Purpose: Returns rows that are in one relation but not in the other.

Notation:

R−S
Example:

Student1−Student2
Result:

RollNo Name
101 Harry

5. Cartesian Product (×):

Purpose: Combines every row of one relation with every row of another.

Notation:

R×S
Example:
Student:

RollNo Name
101 Harry
102 Hermione

Course:
Course
Math
Physics

Student×Course
Result:

RollNo Name Course


101 Harry Math
101 Harry Physics
102 Hermione Math
102 Hermione Physics

Extended Operators in Relational Algebra

Extended operators are those operators which can be derived from basic operators.
There are mainly three types of extended operators in Relational Algebra:
 Join
 Intersection
 Divide

Intersection Operator (∩)


 The Intersection operator finds the common tuples between two relations (tables).
 It returns only the rows that appear in both tables.

Notation:

R∩S

 R and S are two relations (tables) with the same set of attributes (they must have the
same schema for intersection to work).

Example:
Consider two relations:

Student1:
RollNo Name
101 Harry
102 Ron
103 Hermione

Student2:

RollNo Name
102 Ron
103 Hermione
104 Draco

The intersection of these two relations:

Student1∩Student2

Result:

RollNo Name
102 Ron
103 Hermione

Division Operator (÷)


 The division operator is used for "for all" queries — when you want to find entities
related to all items in another set.
 It returns rows from one table that are associated with every row in another table.

Notation:

R÷S
 R (dividend relation): Contains extra attributes compared to S.
 S (divisor relation): Contains a subset of attributes from R.

Result: The division returns all tuples from R that have corresponding matches for every tuple
in S.
Example:
Tables:

StudentCourse (R): — lists which students are taking which courses

Student Course
Harry Math
Harry Physics
Ron Math
Hermione Math
Hermione Physics

Courses (S): — lists courses we want all students to have taken

Course
Math
Physics

Query:

Find students who are enrolled in all courses listed in the Courses table:

StudentCourse ÷ Courses

Result:

Student
Harry
Hermione

How does it work?

The division operator works like this:

1. Identify matches:
o Look at each Student in StudentCourse and check if they are associated with
every Course in Courses.
2. Return qualified tuples:
o If a student has all courses from Courses, they are included in the result.

Join Operation

 The Join operation in relational algebra combines related tuples from two
relations (tables) into a single result set.
 It merges rows based on a common attribute or condition.
The general format is:
R S
Where R and S are relations (tables).

Types of Joins:

Theta Join (θ-Join):

 Combines tuples based on a condition θ (like =, ≠, >, <, etc.).


 Notation:

R⋈θS
Example:
Consider these tables:

Employee:

EmpID Name DeptID


1 Harry 101
2 Ron 102
3 Hermione 103

Department:

DeptID DeptName
101 HR
102 IT

The Theta join:

Employee⋈Employee.DeptID = Department.DeptID

Result:
EmpID Name DeptID DeptName
1 Harry 101 HR
2 Ron 102 IT

2. Equi Join:

 A special case of Theta Join where the condition is only equality (=).
 Same example as above since it uses the condition:

Employee.DeptID = Department.DeptID

3. Natural Join (⋈):

 A simpler form of Equi Join where:


o Matching is automatically done using attributes with the same name in both
tables.
o Duplicates in common columns are removed.

Notation:

R⋈S
Example:

Employee⋈Department
Result (duplicates merged):

EmpID Name DeptID DeptName


1 Harry 101 HR
2 Ron 102 IT

4. Outer Joins:

 Include rows even when there's no match — filling with nulls when needed.
 Left Outer Join (⟕): All rows from R + matching rows from S
 Right Outer Join (⟖): All rows from S + matching rows from R
 Full Outer Join (⟗): All rows from R and S (null where no match)

Example:

Left Outer Join: Employee ⟕ Department


Result:

EmpID Name DeptID DeptName


1 Harry 101 HR
2 Ron 102 IT
3 Hermione 103 NULL

Why use Joins?


 To combine data spread across multiple tables.
 To query relationships — like "Which employees work in which departments?"
 Essential for relational databases where data is normalized (split across tables).

Difference between Natural Join and Equijoin:

1. Equi Join:

 An Equi Join combines rows from two tables based on a specific condition
of equality (=) between attributes.
 You explicitly specify the condition for matching.

Syntax:

R⋈conditionS
Example:

Employee Table:

EmpID Name DeptID


1 Harry 101
2 Ron 102
3 Hermione 103

Department Table:

DeptID DeptName
101 HR
102 IT

Equi Join Query:


Employee ⋈ Employee.DeptID

Result:

EmpID Name DeptID DeptName


1 Harry 101 HR
2 Ron 102 IT

Key points:

 You must explicitly specify the condition (Employee.DeptID =


Department.DeptID).
 The DeptID column appears twice — once from Employee and once from
Department.

✅ 2. Natural Join:

 A Natural Join automatically matches rows based on columns with the


same name in both tables — no need for explicit conditions.
 It removes duplicate columns from the output.

Syntax:

R⋈S
Example:

Using the same Employee and Department tables:

Employee ⋈ Department

Result:

EmpID Name DeptID DeptName


1 Harry 101 HR
2 Ron 102 IT

Key points:

 Automatically joins on the common attribute DeptID.


 Removes duplicate columns — so DeptID only appears once.
Key Differences:

Aspect Equi Join Natural Join


No need for a condition — auto-
Requires an explicit condition
Condition matches columns with the same
(like R.A = S.B).
name.
Column Retains duplicate columns in Removes duplicates — shows
duplication the output. each matching column only once.
Can join on any condition Only joins on equality of columns
Flexibility
(not just equality). with the same name.
R⋈R.A=S.BSR \bowtie_{R.A
Syntax R⋈SR \bowtie SR⋈S
= S.B} SR⋈R.A=S.BS

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy