Skip to the content.

RDBMS:

RDBMS stands for relational database management system. A relational model can be represented as a table of rows and columns. A relational database has following major components:

Table:

A table is a collection of data represented in rows and columns. Each table has a name in database.

Record or Tuple:

Each row of a table is known as record. It is also known as tuple.

Field or Column name or Attribute:

For example if we see student database table, stud_id,stud_name,stud_addr and stud_age are attributes.

Domain:

A domain is a set of permitted values for an attribute in table. For example, a domain of month-of-year can accept January, February,…December as values,a domain of dates can accept all possible valid dates etc. We specify domain of attribute while creating a table.An attribute cannot accept values that are outside of their domains.For example if we declare stud_id as int in student database table so that stud_id cannot accept values that are not integers for example, stud_id cannot has values like, “First”, 10.11 etc.

Instance and Schema:

It is already discussed in intro part please recheck there.

student table

Keys

Candidate Key:

minimal set of attributes which can be uniquely identify a tuple is known as candidate key.For example, STUD_NO in STUDENT relation.

Primary Key:

There can be more than one candidate key in relation out of which one can be choosen as primary key.For example,STUD_NO, as well as STUD_PHONE both, are candidate keys for relation STUDENT but STUD_NO can be chosen as the primary key (only one out of many candidate keys).

Alternate Key:

Out of all candidate keys, only one gets selected as primary key, remaining keys are known as alternate or secondary keys.

Composite Key:

A key that consists of more than one attribute to uniquely identify rows (also known as records & tuples) in a table is called composite key.

Foreign Key:

Foreign keys are the attributes of a table that points to the primary key of another table. They act as a cross-reference between tables.

Introduction to Relation Algebra and Relational Calculus:

In the previous tutorials, we discussed the designing of database using Relational model, E-R diagram and normalization. Now that we have designed the database, we need to store and retrieve data from the database, for this purpose we need to understand the concept of Relational algebra and relational calculus.

Query Language:

A language which is used to store and retrieve data is known as Query language. For example, SQL. These are 2 types:

1. Procedural Query language:

In procedural query language user instructs the system to perform a series of operations to produce desired results. Here users tells what data to be retrieved from database and how to retrieve it. For example, Let’s take a real world example to understand the procedural language, you are asking your younger brother to make a cup of tea, if you are just telling him to make a tea and not telling the process then it is a non-procedural language, however if you are telling the step by step process like switch on the stove, boil the water, add milk etc. then it is a procedural language.

2. Non-procedural query language:

In Non-procedural query language, user instructs the system to produce the desired result without telling the step by step process. Here users tells what data to be retrieved from database but doesn’t tell how to retrieve it.

query language

NOTE:

Relational Algebra:

Relational Algebra is a procedural query language that works on relational model.The purpose of a query language is to retrieve data from database or perform various operations such as insert, update, delete on the data. When I say that relational algebra is a procedural query language, it means that it tells what data to be retrieved and how to be retrieved.

Types Of Operations in Relational Algebra:

Basic/Fundamental Operations:

Table: CUSTOMER
---------------

Customer_Id     Customer_Name      Customer_City
-----------     -------------      -------------
C10100           Steve              Agra
C10111           Raghu              Agra
C10115           Chaitanya          Noida
C10117           Ajeet              Delhi
C10118           Carl               Delhi

Select Operator (σ):

Query:

σ Customer_City=”Agra” (CUSTOMER)

output:

Customer_Id   Customer_Name    Customer_City
-----------   -------------    -------------
C10100        Steve            Agra
C10111        Raghu            Agra

Project Operator (∏):

Query:

∏ Customer_Name, Customer_City (CUSTOMER)

Output:

Customer_Name      Customer_City
-------------      -------------
Steve              Agra
Raghu              Agra
Chaitanya          Noida
Ajeet              Delhi
Carl               Delhi

Union Operator(∪):

Table 1: COURSE

Course_Id  Student_Name   Student_Id
---------  ------------   ----------
C101        Aditya         S901
C104        Aditya         S901
C106        Steve          S911
C109        Paul           S921
C115        Lucy           S931
Table 2: STUDENT

Student_Id     Student_Name   Student_Age
------------   ----------     -----------
S901           Aditya         19
S911           Steve          18
S921           Paul           19
S931           Lucy           17
S941           Carl           16
S951           Rick           18

Query:

∏ Student_Name (COURSE) ∪ ∏ Student_Name (STUDENT)

Output:

Student_Name
------------
Aditya
Carl
Paul
Lucy
Rick
Steve

Intersection Operator (∩):

Query :

∏ Student_Name (COURSE) ∩ ∏ Student_Name (STUDENT)

Output :

Student_Name
------------
Aditya
Steve
Paul
Lucy

Set Difference (-):

Query : ∏ Student_Name (STUDENT) - ∏ Student_Name (COURSE)

Output :

Student_Name
------------
Carl
Rick

Cartesian product (X) :

Table 1: R

Col_A    Col_B
-----    ------
AA        100
BB        200
CC        300 
Table 2: S

Col_X     Col_Y
-----     -----
XX         99
YY         11
ZZ         101

Query :

R X S

Output :

Col_A    Col_B     Col_X     Col_Y
-----    ------    ------    ------
AA        100      XX         99
AA        100      YY         11
AA        100      ZZ         101
BB        200      XX         99
BB        200      YY         11
BB        200      ZZ         101
CC        300      XX         99
CC        300      YY         11
CC        300      ZZ         101

Rename (ρ) :

Table: CUSTOMER

Customer_Id     Customer_Name      Customer_City
-----------     -------------      -------------
C10100           Steve              Agra
C10111           Raghu              Agra
C10115           Chaitanya          Noida
C10117           Ajeet              Delhi
C10118           Carl               Delhi

Query :

ρ(CUST_NAMES, ∏(Customer_Name)(CUSTOMER))

Output :

CUST_NAMES
----------
Steve
Raghu
Chaitanya
Ajeet
Carl

Relational Calculus :

Relational calculus is a non-procedural query language that tells the system what data to be retrieved but doesn’t tell how to retrieve it.

relational calculus

Tuple Relational Calculus :

First_Name     Last_Name     Age
----------     ---------     ----
Ajeet          Singh         30
Chaitanya      Singh         31
Rajeev         Bhatia        27
Carl           Pratap        28

Query to display all the details of students where Last name is ‘Singh’ :

{ t | Student(t) AND t.Last_Name = 'Singh' }

Output :

First_Name     Last_Name     Age
----------     ---------     ----
Ajeet          Singh         30
Chaitanya      Singh         31

Domain Relational Calculus :

Query to find the first name and age of students where student age is greater than 27 :

{< First_Name, Age > | ∈ Student ∧ Age > 27}

Output :

First_Name     Age
----------     ----
Ajeet          30
Chaitanya      31
Carl           28