Join Type and Calculas
Join Type and Calculas
Database Language
• A DBMS has appropriate languages and
interfaces to express database queries and
updates.
• Database languages can be used to read, store
and update the data in the database.
Types of Database Language
Data Definition Language (DDL)
• DDL is used for specifying the database schema. It is used for
creating tables, schema, indexes, constraints etc. in database. Lets
see the operations that we can perform on database using DDL:
• To create the database instance – CREATE
• To alter the structure of database – ALTER
• To drop database instances – DROP
• To delete tables in a database instance – TRUNCATE
• To rename database instances – RENAME
• To drop objects from database such as tables – DROP
• To Comment – Comment
• All of these commands either defines or update the database
schema that’s why they come under Data Definition language.
Data Manipulation Language (DML)
• DML is used for accessing and manipulating
data in a database. The following operations
on database comes under DML:
• To read records from table(s) – SELECT
• To insert record(s) into the table(s) – INSERT
• Update the data in table(s) – UPDATE
• Delete all the records from the table – DELETE
Data Control language (DCL)
• DCL is used for granting and revoking user
access on a database –
• To grant access to user – GRANT
• To revoke access from user – REVOKE
Transaction Control Language(TCL)
• The changes in the database that we made
using DML commands are either performed or
rollbacked using TCL.
• To persist the changes made by DML
commands in database – COMMIT
• To rollback the changes made to the database
– ROLLBACK
CREATE DATABASE Statement
• Syntax:
We use CREATE DATABASE statement in order
to create a database. This is how it is used:
• CREATE DATABASE DBName;Here DBName can
be any string that would represent the
database name.
• Example – The below statement would create
a database named employee
Query Languages
• Language in which user requests information from the
database.
• Categories of languages
– procedural
– non-procedural
• “Pure” languages:
– Relational Algebra
– Tuple Relational Calculus
– Domain Relational Calculus
• Pure languages form underlying basis of query languages
that people use.
Relational Algebra
• Procedural language
• Relational operators are of two types:
• Traditional set Special operators
– Union - Selection
– Intersection - Projection
– set difference - Join
– Cartesian product - Division
• The operators take one or more relations as
inputs and give a new relation as a result.
Traditional Operators
• Union: in mathematical set theory union of
two sets is the set of elements belonging to
both sets. It is denoted by U.
S1={1,2,3,4}
S2={5,6,7,8} the union of these two would be
S3={1,2,3,4,5,6,7,8} Cust_nam Cust_stat
e us
Cust_name Cust_Status Cust_name Cust_Status Rahul Good
Rahul Good Raman Average
Sumit Excellent
Sumit Excellent Rahul Good
Raman Average
Traditional Operators
• Intersection: in mathematics intersection of
two sets produces a set containing common
elements of both sets
A B
A-B= Cust_name Cust_status
Sumit Excellent
Cust_name Cust_status
B-A= Raman Average
Cartesian-Product Operation-Example
Select Operation – Example
Select Operation ()
• Notation: p(r)
• p is called the selection predicate
• Defined as:
p(r) = {t | t r and p(t)}
Where p is a formula in propositional calculus consisting of
terms connected by : (and), (or), (not)
Each term is one of:
<attribute> op <attribute> or <constant>
where op is one of: =, , >, . <.
• Example of selection:
branch-name=“Perryridge”(account)
Project Operation – Example
Project Operation
• Notation:
103 25000
103 Harry
Employee Salary
Operation: (EMPLOYEE ⋈ SALARY)
EMP_CODE EMP_NAME SALARY
Employee Salary
EMP_NAME SALARY
Stephan 50000
Jack 30000
Harry 25000
Outer Join
• The outer join operation is an extension of the
join operation. It is used to deal with missing
information.
Types of outer join
• Left outer join
• Right outer join
• Full outer join
(EMPLOYEE ⋈ FACT_WORKERS)
Employee
EMP_NAME STREET CITY
1 John 1 Delhi
2 Harry 2 Mumbai
3 Jackson 3 Noida
1 John 1 Delhi
2 Harry 2 Mumbai
3 Harry 3 Noida
CUSTOMER ⋈ PRODUCT
Relational Calculus
• Relational calculus is a non-procedural query
language. In the non-procedural query language, the
user is concerned with the details of how to obtain
the end results.
• The relational calculus tells what to do but never
explains how to do.
Types of Relational calculus
Tuple Relational Calculus (TRC)
• The tuple relational calculus is specified to select the
tuples in a relation. In TRC, filtering variable uses the
tuples of a relation.
• The result of the relation can have one or more
tuples.
• Notation
• {T | P (T)} or {T | Condition (T)}
Tuple Relational Calculus (TRC)
• Query to display the last name of those students where age is
greater than 30
• { t.Last_Name | Student(t) AND t.age > 30 }
• Output
Difference between relational algebra and
calculus
S.NO Relational Algebra Relational Calculus
While Relational Calculus is
1. It is a Procedural language.
Declarative language.