DBMS Concepts

DBMS Tutorial Components of DBMS. Applications of DBMS The difference between file system and DBMS. Types of DBMS DBMS Architecture DBMS Schema Three Schema Architecture. DBMS Languages.

DBMS ER Model

ER model: Entity Relationship Diagram (ERD) Components of ER Model. DBMS Generalization, Specialization and Aggregation.

DBMS Relational Model

Codd’s rule of DBMS Relational DBMS concepts Relational Integrity Constraints DBMS keys Convert ER model into Relational model Difference between DBMS and RDBMS Relational Algebra DBMS Joins

DBMS Normalization

Functional Dependency Inference Rules Multivalued Dependency Normalization in DBMS: 1NF, 2NF, 3NF, BCNF and 4NF

DBMS Transaction

What is Transaction? States of transaction ACID Properties in DBMS Concurrent execution and its problems DBMS schedule DBMS Serializability Conflict Serializability View Serializability Deadlock in DBMS Concurrency control Protocols

Difference

Difference between DFD and ERD

Misc

Advantages of DBMS Disadvantages of DBMS Data Models in DBMS Relational Algebra in DBMS Cardinality in DBMS Entity in DBMS Attributes in DBMS Data Independence in DBMS Primary Key in DBMS Foreign Key in DBMS Candidate Key in DBMS Super Key in DBMS Aggregation in DBMS Hashing in DBMS Generalization in DBMS Specialization in DBMS View in DBMS File Organization in DBMS What Is A Cloud Database What Is A Database Levels Of Locking In DBMS What is RDBMS Fragmentation in Distributed DBMS What is Advanced Database Management System Data Abstraction in DBMS Checkpoint In DBMS B Tree in DBMS BCNF in DBMS Advantages of Threaded Binary Tree in DBMS Advantages of Database Management System in DBMS Enforcing Integrity Constraints in DBMS B-Tree Insertion in DBMS B+ Tree in DBMS Advantages of B-Tree in DBMS Types of Data Abstraction in DBMS Levels of Abstraction in DBMS 3- Tier Architecture in DBMS Anomalies in Database Management System Atomicity in Database Management System Characteristics of DBMS DBMS Examples Difference between Relational and Non-Relational Databases Domain Constraints in DBMS Entity and Entity set in DBMS ER Diagram for Banking System in DBMS ER Diagram for Company Database in DBMS ER Diagram for School Management System in DBMS ER Diagram for Student Management System in DBMS ER Diagram for University Database in DBMS ER Diagram of Company Database in DBMS Er Diagram Symbols and Notations in DBMS How to draw ER-Diagram in DBMS Integrity Constraints in DBMS Red-Black Tree Deletion in DBMS Red-Black Tree Properties in DBMS Red-Black Tree Visualization in DBMS Redundancy in Database Management System Secondary Key in DBMS Structure of DBMS 2-Tier Architecture in DBMS Advantages and Disadvantages of Binary Search Tree Closure of Functional Dependency in DBMS Consistency in Database Management System Durability in Database Management System ER Diagram for Bank Management System in DBMS ER Diagram for College Management System in DBMS ER Diagram for Hotel Management System in DBMS ER Diagram for Online Shopping ER Diagram for Railway Reservation System ER Diagram for Student Management System in DBMS Isolation in DBMS Lossless Join and Dependency Preserving Decomposition in DBMS Non-Key Attributes in DBMS Data Security Requirements in DBMS DBMS functions and Components What is Homogeneous Database? DBMS Functions and Components Advantages and Disadvantages of Distributed Database Relational Database Schema in DBMS Relational Schema

DBMS Joins: Inner, Outer, Natural and Self Join

Joins are the combination of related tuples from the two different relations or tables into a single type. It is similar to the Cartesian product except the fact that in Cartesian product operation, a user gets all the possible combinations of relations. While in joins operation use

r gets only those combinations that satisfy some matching conditions between two relations. A relation can also join to itself, which is called as a self-join.

Join operation combines two tuples from different relations if and only if the following conditions are satisfied:

  • There must be a common attribute in both the relation.
  • Join condition must be satisfied.
Join = Cross Product + Condition

There are following different type of joins:

  1. Inner Join or Equi Join
  2. Outer Join
  3. Natural join
  4. Self-join

1. Inner Join or Equi Join

Inner Join or Equi Join is represented by (=) equal sign and displays all the records which are common between two relations. If no record is selected, return NULL. The query of Inner join compares each tuple of Relation1 with each tuple of Relation2 to find all pairs of rows which satisfy the join condition. When the join condition is satisfied, attribute values for each matched pair of tuples of A and B are combined into a resultant tuple.

DBMS Joins

Syntax:

Relation1.attribute_name = Relation2.attribute_name

Example:

Table: student

Student_id Name Age
101 RS 20
102 TK 21
103 Sk 20

Table: Course

Course_id Student_id Course_name
401 101 B.tech
402 102 MCA
403 103 MCA

Query: Display the name of student who study in each course

  • ? Name(?(student.Student_id =Course.Student_id)(student x course))

Output:

Name
RS
TK
Sk

2. Outer Join

The Outer Join displays all records from both the participating relation which satisfy the join condition along with tuples which do not satisfy the join condition.

An outer join is mainly of three types:

  1. Left Outer join
  2. Right Outer join
  3. Full Outer join

Left Outer Join

The left outer join is represented by (?) symbol and displays all the tuples from the left relation and the matching tuples from the right relation. If there is exists no matching record in the right relation, it displays the NULL value.

DBMS Joins 1

Syntax:

Relation1 ? Relation2

Example:

Table: student

Student_id Name Age
101 RS 20
102 TK 21
103 Sk 20
104 Pk 21

Table: Course

Course_id Student_id Course_name
401 101 B.tech
402 102 MCA
403 103 MCA
  • (Student ? Course)

Output:

Student_id Name Age Course_id Course_name
101 RS 20 401 B.tech
102 TK 21 402 MCA
103 Sk 20 403 MCA
104 Pk 21 NULL NULL

Right Outer Join

The right outer join is represented by (?) symbol and displays all the tuples from the right relation and the matching tuples from the left relation. If there is exists no matching record in the left relation, it displays the NULL value.

DBMS Joins 2

Syntax:

Relation1 ?Relation2

Example:

Table: student

Student_id Name Age
101 RS 20
102 TK 21
103 Sk 20

Table: Course

Course_id Student_id Course_name
401 101 B.tech
402 102 MCA
403 103 MCA
404   MBA
  • (student ? Course)

Output:

Student_id Name Age Course_id Course_name
101 RS 20 401 B.tech
102 TK 21 402 MCA
103 Sk 20 403 MCA
NULL NULL NULL 404 MBA

Full Outer Join

The full outer join is represented by(?) symbol and combines the results of both right and left outer joins and returns all (matching or unmatching) records from both the relation.

DBMS Joins 3

Syntax:

Relation1 ? Relation2

Example:

Table: student

Student_id Name Age
101 RS 20
102 TK 21
103 Sk 20

Table: Course

Course_id Student_id Course_name
401 101 B.tech
402 102 MCA
404   MBA
  • (student ? Course)

Output:

Student_id Name Age Course_id Course_name
101 RS 20 401 B.tech
102 TK 21 402 MCA
103 Sk 20 NULL NULL
NULL NULL NULL 404 MBA

3. Natural Join

Natural Join is represented by a (?) symbol, and it is a type of Inner join which is based on attributes having the same name and datatype present in both the relations to get joined.

Difference between Inner join and Natural join

  • Inan inner join, a user has to specify a join condition to join the two relations. Whereas in the natural join, a user doesn't specify a join condition. Users just write the two relation names without any condition. Then the natural join will automatically check for equality between the records for every column existing in both relation.
DBMS Joins 4

Syntax:

Relation1 ?Relation2

Example:

Table: student

Student_id Name Age
101 RS 20
102 TK 21
103 Sk 20

Table: Course

Course_id Student_id Course_name
401 101 B.tech
402 102 MCA
  • (student ? Course)

Output:

Student_id Name Age Course_id Course_name
101 RS 20 401 B.tech
102 TK 21 402 MCA

4. Self-Join

A self-join is a join in which a relation is joined with itself (which is also known as Unary relationship), especially when the relation has a foreign key which references to its own primary key. To join a relation to itself means that each tuple of the relation is combined with itself and with every other tuple of the relation. It can be viewed as a join of two copies of the same relation.

DBMS Joins 5

Example:

Table: student

student_id Name Course Class_representative
101 RS MCA 101
102 TK MBA NULL
103 Sk MCA 101
104 Pk MBA NULL

Query: Display the name of student who are class representative

  • ? a.student_id, a.Name,b.Course, b.Name(? a.student_id = b.Class_representative) (a.student x b.student))

Output:

student_id Name Course name
101 RS MCA RS
101 RS MCA SK