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 Transaction Processing in DBMS Discriminator in DBMS

Relational Algebra in DBMS

Relational Algebra is a widely used procedural query language, which takes instances of one or more relation as an input and generates a new relation as an output. It uses a different set of operators (like unary or binary operators) and operands to perform queries. EF Codd created the relational algebra for relational database. 
The relational algebra provides a query language in which all tuples or rows of data are accessed in one statement without the use of loops, etc.

The operators that are used to perform relational algebra are:

  1. Basic Operators
  2. Derived Operators

Basic Operators

  • SELECT (?)
  • PROJECT (?)
  • RENAME ( ? )
  • UNION (?)
  • DIFFERENCE (-)
  • CARTESIAN PRODUCT ( x )

Project Operator(?)

The project operator is represented by the pie(?) symbol, which is used to access the values of specified columns or attributes from a table or a relation.

Syntax: ? (R)

In the above syntax, R is the name of a relation or table and C1, C2 C3…. CN are the attributes or columns name of the relation.

Example:

Table Student:

Rollno Name Age
101 A 20
102 B 21
103 C 20
104 D 20


Query: Retrieve the Rollno from the above table Student

  • ?Rollno(Student)

Output:

Rollno
101
102
103
104

Select Operator(?)

The select operator is represented by the sigma(?) symbol, which is used to fetch the tuples (rows) from the relation that satisfies the selection condition. We cannot fetch the attributes of a relation using this command.

Syntax: ?(R)

In the above syntax, R is a relation or name of a table, and the condition is a propositional logic which uses the relational operators like ?, <,=,>, ?.

Example:

Table Student:

Rollno Name Age
101 A 20
102 B 21
103 C 20
104 D 20


Query: Retrieve the name of Rollno 102 from the above table Student

  • ?Name(? Rollno=102(Student))

Output:

Name
B

Rename Operator( ? )

The rename operator is denoted by the rho() symbol. It is used to rename a relation or an attribute of the relation.

Syntax:  ? (new_Relation_name,old_Relation_name)

Example:

Table Student:

Rollno Name Age
101 A 20
102 B 21
103 C 20
104 D 20


Query: Rename the name of Student relation to student1.

  • (student1,Student)

Union Operator (?)

The union operator is represented by the (?)symbol, which is used to display all the tuples (rows) from two relations. It is a binary operation because to apply this operation user must require a minimum of two relations.

For a valid union operation, both the table should have same number of attributes to combine them. Duplicate data are eliminated during the union operation.

Syntax: R1 U R2

In the above syntax, R1 is the name of the first relation or table, and R2 is the name of the second relation or table.

Example:

Table Student:                                                                    

Rollno Name
 101 A
102 B
 103 C
104 D

Table Employee:

Employee_id Name
 201 P
202 Q
 203 R
204 S


Query: Combine the table Student with another table Employee

  • (Student)U(Employee)

Output:

Rollno Name
 101 A
102 B
 103 C
104 D
 201 P
202 Q
 203 R
204 S

Set Difference (-)

The set difference operation is represented by the minus (-) sign, which is used to display all the tuples (rows) that are in the first relation but not in the second relation.

Syntax: R1 – R2

In the above syntax, R1 is the name of the first relation or table, and R2 is the name of the second relation or table.

Example:

Table Student:                                                                    

Rollno Name
 101 A
102 B
 103 C
104 D

Table Employee:

Employee_id Name
 101 A
202 Q
 103 C
204 S
  • (Student)-(Employee)

Output:

Rollno Name
102 B
104 D

Cartesian Product (x)

It is represented by the cross (x) symbol, which is used to combine each tuple in one relation with each tuple in another relation. This operation is also known as a cross product.

Syntax: R1 x R2

In the above syntax, R1 is the name of the first relation or table, and R2 is the name of the second relation or table. If the relation R1 contains x columns and m rows, and relation R2 contains y columns and n rows, the resultant table will contain x+y columns and m*n rows.

Example:

Table T1:                                                                    

Column1 Column2 Column3
 101 A 12
102 B 21
 103 C 20
104 D 31

Table T2:

columnA ColumnB
 101 A
202 Q
  • (T1)X(T2)

Output:

Column1 Column2 Column3 columnA ColumnB
 101 A 12  101 A
 101 A 12 202 Q
102 B 21  101 A
102 B 21 202 Q
 103 C 20  101 A
 103 C 20 202 Q
104 D 31  101 A
104 D 31 202 Q

Derived Operators

Derived operators are the operators which can be obtained from the basic operators and consists of following three types:

  • INTERSECTION ( ? )
  • JOINS (?)
  • DIVISION(/)

Intersection Operator (?)

The intersection operator is represented by the (?) symbol, which is used to display all the tuples or rows of common attributes from two relations. It is also a binary operator.

Syntax: R1 ?  R2

In the above syntax, R1 is the name of the fist relation or table, and R2 is the name of the second relation or table.

Example:

Table Student:                                                                    

Rollno Name
 101 A
102 B
 103 C
104 D

Table Employee:

Employee_id Emp_Name
 101 A
202 Q
 103 C
204 S
  • ? Name (Student) ? ? Emp_Name (Employee) 

Output

Name
A
C

Joins

A join operation is represented by ?(Bowtie) Symbol. Joins are the combination of related tuples from two different relations or tables into a single type. It is similar to a Cartesian product. In Cartesian product operation, a user gets all the possible combinations of relations. But in join operation, a user 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.

Division Operator ( / )

The division operator is represented by the division (/) symbol, which can be applied if and only if:

  • Attributes of a relation B is a proper subset of attributes of a relation A.
  • The resultant relation will have the attributes = (All attributes of relation A – All attributes of relation B).
  • The relation or table returned by the division operator will display those tuples from relation A, which are associated with every B’s relation tuple.

Example:
Table: Enrolled

Sid Cid
S1 C1
S2 C1
S1 C2
S3 C2

Table: Course

Cid
C1
C2

Query: Retrieve the student_id of students who enrolled in every course.

  • ?Sid (Enrolled) – (?Sid ( (?Sid(Enrolled)) x ( ?Cid (Course) ) ) – (Enrolled) )

Output:

Sid
S1