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

Module 2 dbms Q&A

The document outlines the Relational Model, detailing its key components such as relations, tuples, attributes, domains, and schemas. It also discusses various types of keys, integrity constraints, and operations in relational algebra, including fundamental and additional operations, as well as the differences between relational algebra and relational calculus. Additionally, it provides examples of relational algebra queries for different scenarios involving students, employees, and doctors.

Uploaded by

dusra morr
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)
2 views

Module 2 dbms Q&A

The document outlines the Relational Model, detailing its key components such as relations, tuples, attributes, domains, and schemas. It also discusses various types of keys, integrity constraints, and operations in relational algebra, including fundamental and additional operations, as well as the differences between relational algebra and relational calculus. Additionally, it provides examples of relational algebra queries for different scenarios involving students, employees, and doctors.

Uploaded by

dusra morr
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/ 6

Module-2: Relational Model

1. What is the Relational Model? Key components with examples [5 Marks]

Relational Model is a way to organize data into tables (relations) consisting of rows (tuples) and
columns (attributes).

Key Components:

• Relation (Table):
A set of tuples sharing the same attributes.
Example: Students(StudentID, Name, Age)

• Tuple (Row):
A single entry in a table.
Example: (101, "John", 21)

• Attribute (Column):
A property/characteristic of a relation.
Example: Name, Age.

• Domain:
Set of allowed values for an attribute.
Example: Domain of "Age" is integers between 0–100.

• Schema:
Structure of a table.
Example: Students(StudentID: int, Name: varchar, Age: int)

2. Different types of Keys in Relational Model [5 Marks]

Keys uniquely identify tuples in a relation.

Types:

• Primary Key:
Unique and non-null.
Example: StudentID in Students table.

• Candidate Key:
All possible unique keys.
Example: StudentID and Email (if both are unique).

• Super Key:
A set of attributes that uniquely identify a tuple.
Example: {StudentID, Name} is a Super Key.

• Foreign Key:
Links one relation to another.
Example: StudentID in Enrollment table referencing Students table.
• Alternate Key:
Candidate keys other than the primary key.

3. Integrity Constraints in Relational Model [5 Marks]

Integrity constraints ensure correctness of data.

Types:

• Domain Constraint:
Attribute values must be from a valid domain.
Example: Age must be a number, not text.

• Entity Integrity:
Primary key cannot be NULL.

• Referential Integrity:
Foreign key must match primary key in another table.

• Key Constraint:
No two tuples can have the same value for a key attribute.

4. Relational Algebra - Fundamental and Additional Operations [5 Marks]

Relational Algebra = Procedural query language using set operations.

Fundamental Operations:

• Select (σ): Pick rows.


σ Age > 20 (Students)

• Project (π): Pick columns.


π Name, Age (Students)

• Union (∪): Combine two relations.

• Set Difference (−): Rows in one but not in other.

• Cartesian Product (×): All pair combinations.

• Rename (ρ): Rename relation/attributes.

Additional Operations:

• Intersection (∩)

• Natural Join (⋈)

• Theta Join (⋈_θ)

• Division (÷)

5. Relational Algebra vs Relational Calculus [5 Marks]


Feature Relational Algebra Relational Calculus

Type Procedural Non-Procedural

How it Works Specifies "how" to retrieve data Specifies "what" data to retrieve

Based on Operations like Select, Project, Join Logical expressions

Focus Sequence of operations Desired result

6. Various Joins in Relational Algebra with Examples [5 Marks]

• Theta Join (⋈_θ): Join based on a condition.


Example: Students ⋈_Students.DeptID = Dept.DeptID Dept

• Equi Join: Theta join with only "=" condition.

• Natural Join (⋈): Automatically joins on common attributes.

• Outer Joins:

o Left Outer Join: All from left + matched from right.

o Right Outer Join: All from right + matched from left.

o Full Outer Join: All from both even if unmatched.

7. Importance of Relational Algebra in DBMS [5 Marks]

• Foundation of SQL.

• Helps in query optimization.

• Provides theoretical base for database operations.

• Enables precise data retrieval.

• Formal language to describe database operations.

8. Relational Algebra Query: Students Enrolled in "Database Systems" [10 Marks]

Given Schema:
Students(StudentID, Name, Age, Department)
Courses(CourseID, CourseName, Credits)
Enrollment(StudentID, CourseID, Grade)

Approach:

1. Select CourseID of "Database Systems".


σ CourseName = 'Database Systems' (Courses)
2. Find matching StudentIDs in Enrollment.
Enrollment ⨝ Enrollment.CourseID = Courses.CourseID

3. Retrieve names from Students.


Result = π Name (Students ⨝ Students.StudentID = Enrollment.StudentID)

9. Relational Algebra Query: Employees in HR and Salary > $50,000 [10 Marks]

Given Schema:
Employee(EmpID, Name, Department, Salary)
Department(DeptID, DeptName, ManagerID)
WorksIn(EmpID, DeptID)

Approach:

1. Select DeptID of 'HR' from Department.


σ DeptName = 'HR' (Department)

2. Find employees in WorksIn matching HR.


WorksIn ⨝ WorksIn.DeptID = Department.DeptID

3. Select Employees with Salary > 50000.


σ Salary > 50000 (Employee ⨝ WorksIn)

4. Result: π Name (Final Result)

10. Relational Algebra Query: Students who borrowed books by J.K. Rowling [10 Marks]

Given Schema:
Books(BookID, Title, Author, Publisher)
Borrowed(BookID, StudentID, DueDate)
Students(StudentID, Name, Age)

Approach:

1. Select BookIDs written by 'J.K. Rowling'.


σ Author = 'J.K. Rowling' (Books)

2. Join Borrowed and Books on BookID.

3. Join result with Students on StudentID.

4. Result: π Name (Students who borrowed Rowling's books)

11. Relational Algebra Query: Customers Ordered Electronics [10 Marks]

Given Schema:
Customers(CustomerID, Name, Age, City)
Orders(OrderID, CustomerID, ProductID, OrderDate)
Products(ProductID, ProductName, Price, Category)
Approach:

1. Select ProductIDs where Category = 'Electronics'.

2. Join Products and Orders on ProductID.

3. Join with Customers on CustomerID.

4. Result: π Name (Customers)

12. Relational Algebra Query: Doctors Treating Diabetes Patients [10 Marks]

Given Schema:
Patients(PatientID, Name, Age, Disease)
Doctors(DoctorID, Name, Specialty)
Treats(DoctorID, PatientID)

Approach:

1. Select PatientIDs with Disease = 'Diabetes'.

2. Join Treats and Patients on PatientID.

3. Join with Doctors on DoctorID.

4. Result: π Name (Doctors)

13. Relational Calculus and Difference from Relational Algebra [5 Marks]

Relational Calculus = Non-procedural query language that defines what to retrieve, not how.

• Based on mathematical predicate logic.

• Focuses on properties of required result.

Feature Relational Algebra Relational Calculus

Procedural Yes No

Focus How to fetch What to fetch

Basis Operations Logic Formulas

14. Tuple Relational Calculus (TRC) with Example [5 Marks]

Tuple Relational Calculus (TRC) expresses queries by describing the properties of desired tuples.

Syntax:

{ t | P(t) }
where t = tuple variable, P(t) = condition.

Example:
Find Students older than 20:
{ t | t ∈ Students ∧ t.Age > 20 }

15. Relational Algebra: Names, Age of Students Older than 20 [5 Marks]

Given: STUDENT(Roll#, Name, Age, City)

Query:
π Name, Age (σ Age > 20 (STUDENT))

16. Relational Algebra: Employees in HR and Salary > 40000 [5 Marks]

Given: Employee(EID#, E_Name, Designation, Salary)

Query:
π E_Name (σ Designation = 'HR' ∧ Salary > 40000 (Employee))

You might also like