DBMS PPT (1).pptx
DBMS PPT (1).pptx
A Database Management System (DBMS) is a software system that is designed to manage and
organize data in a structured manner. It allows users to create, modify, and query a database, as
well as manage the security and access controls for that database.
Data storage and retrieval: A DBMS is responsible for storing and retrieving data from the
database, and can provide various methods for searching and querying the data.
Concurrency control: A DBMS provides mechanisms for controlling concurrent access to the
database, to ensure that multiple users can access the data without conflicting with each other.
Data integrity and security: A DBMS provides tools for enforcing data integrity and
security constraints, such as constraints on the values of data and access controls that
restrict who can access the data.
Backup and recovery: A DBMS provides mechanisms for backing up and recovering the
data in the event of a system failure.
DBMS can be classified into two types: Relational Database Management System
(RDBMS) and Non-Relational Database Management System (NoSQL or Non-SQL)
RDBMS: Data is organized in the form of tables and each table has a set of rows and
columns. The data are related to each other through primary and foreign keys.
File based systems were an early attempt to computerize the manual system. It is also called
a traditional based approach in which a decentralized approach was taken where each
department stored and controlled its own data with the help of a data processing specialist.
The main role of a data processing specialist was to create the necessary computer file
structures, and also manage the data within structures and design some application
programs that create reports based on file data.
Consider an example of a student's file system. The student file will contain information
regarding the student (i.e. roll no, student name, course etc.). Similarly, we have a subject file
that contains information about the subject and the result file which contains the information
regarding the result.
Some fields are duplicated in more than one file, which leads to data redundancy. So to
overcome this problem, we need to create a centralized system, i.e. DBMS approach.
DBMS:
A database approach is a well-organized collection of data that are related in a
meaningful way which can be accessed by different users but stored only once in a
system. The various operations performed by the DBMS system are: Insertion, deletion,
selection, sorting etc.
Disadvantages of File System:
Redundancy of data: Data is said to be redundant if the same data is copied at many places.
If a student wants to change their Phone number, he or she has to get it updated in various
sections. Similarly, old records must be deleted from all sections representing that student.
Inconsistency of Data: Data is said to be inconsistent if multiple copies of the same data do
not match each other. If the Phone number is different in Accounts Section and Academics
Section, it will be inconsistent. Inconsistency may be because of typing errors or not
updating all copies of the same data.
Difficult Data Access: A user should know the exact location of the file to access data, so the
process is very cumbersome and tedious. If the user wants to search the student hostel
allotment number of a student from 10000 unsorted students’ records, how difficult it can
be.
Unauthorized Access: File Systems may lead to unauthorized access to data. If a student gets
access to a file having his marks, he can change it in an unauthorized way.
No Concurrent Access: The access of the same data by multiple users at the same time is
known as concurrency. The file system does not allow concurrency as data can be accessed
by only one user at a time.
No Backup and Recovery: The file system does not incorporate any backup and recovery of
data if a file is lost or corrupted.
Advantages of DBMS
Data organization: A DBMS allows for the organization and storage of data in a structured
manner, making it easy to retrieve and query the data as needed.
Data integrity: A DBMS provides mechanisms for enforcing data integrity constraints,
such as constraints on the values of data and access controls that restrict who can access
the data.
Concurrent access: A DBMS provides mechanisms for controlling concurrent access to the
database, to ensure that multiple users can access the data without conflicting with each
other.
Data security: A DBMS provides tools for managing the security of the data, such as
controlling access to the data and encrypting sensitive data.
Backup and recovery: A DBMS provides mechanisms for backing up and recovering the
data in the event of a system failure.
Data sharing: A DBMS allows multiple users to access and share the same data, which can
be useful in a collaborative work environment.
Disadvantages of DBMS
Performance overhead: The use of a DBMS can add overhead to the performance of an
application, especially in cases where high levels of concurrency are required.
Scalability: The use of a DBMS can limit the scalability of an application, since it requires
the use of locking and other synchronization mechanisms to ensure data consistency.
Cost: The cost of purchasing, maintaining and upgrading a DBMS can be high, especially
for large or complex systems.
Limited Use Cases: Not all use cases are suitable for a DBMS, some solutions don’t need
high reliability, consistency or security and may be better served by other types of data
storage.
Basics File System DBMS
The file system is a way of
DBMS is software for managing
Structure arranging the files in a storage
the database.
medium within a computer.
Data
Redundant data can be present In DBMS there is no redundant
Redundan in a file system. data.
cy
Backup It doesn’t provide Inbuilt It provides in house tools for
and mechanism for backup and backup and recovery of data
Recovery recovery of data if it is lost. even if it is lost.
There are different fields where a database management system is utilized. Following are a
few applications which utilize the information base administration framework –
Banking –
Database the executive’s framework is utilized to store the exchange data of the client in the
information base.
Education Sector –
Presently, assessments are led online by numerous schools and colleges. They deal with all
assessment information through the data set administration framework (DBMS). In spite
of that understudy’s enlistments subtleties, grades, courses, expense, participation,
results, and so forth all the data is put away in the information base.
Account –
The information base administration framework is utilized for putting away data about
deals, holding and acquisition of monetary instruments, for example, stocks and bonds in
a data set.
Online Shopping –
These days, web-based shopping has become a major pattern. Nobody needs to visit the
shop and burn through their time. Everybody needs to shop through web based
shopping sites, (for example, Amazon, Flipkart, Snapdeal) from home. So all the items
are sold and added uniquely with the assistance of the information base administration
framework (DBMS). Receipt charges, installments, buy data these are finished with the
assistance of DBMS.
Human Resource Management –
Big firms or organizations have numerous specialists or representatives working under
them. They store data about worker’s compensation, assessment, and work with the
assistance of an information base administration framework (DBMS).
Manufacturing –
Manufacturing organizations make various kinds of items and deal them consistently.
To keep the data about their items like bills, acquisition of the item, amount, inventory
network the executives, information base administration framework (DBMS) is utilized.
Data retrieval: DBMS provides a way to retrieve data quickly and easily using search
queries.
Data manipulation: DBMS provides tools to manipulate data, such as sorting, filtering,
and aggregating data.
Security: DBMS provides security features to ensure that only authorized users have
access to the data.
Data backup and recovery: DBMS provides tools to back up data and recover it in case of
system failures or data loss.
Multi-user access: DBMS allows multiple users to access and modify data
simultaneously.
Reporting and analysis: DBMS provides tools to generate reports and analyze data to
gain insights and make informed decisions.
Database Languages
CREATE: to create a database and its objects like (table, index, views, store procedure,
function, and triggers)
TRUNCATE: remove all records from a table, including all spaces allocated for the
records are removed
GRANT: grant permissions to the user for running DML(SELECT, INSERT, DELETE,…)
commands on the table
REVOKE: revoke permissions to the user for running DML(SELECT, INSERT, DELETE,…)
command on the specified table
Transactional Control Language
TCL is short for Transactional Control Language which acts as an manager for all types of
transactional data and all transactions.Some of the command of TCL are
Save Point: It is used to save the data on the temporary basis in the database
DBMS Architecture:DBMS architecture is depending on its
design and can be of the following types:
1)Centralized
2)Decentralized
3)Hierarchical
One tier architecture:
One tier architecture has all the layers such as Presentation, Business, Data Access
layers in a single software package. Applications which handles all the three tiers such
as MP3 player, MS Office are come under one tier application. The data is stored in the
local system or a shared drive.
Two-Tier Architecture:
1. Client Application (Client Tier)
2. Database (Data Tier)
Client system handles both Presentation and Application layers and Server system
handles Database layer. It is also known as client server application. The
communication takes place between the Client and the Server. Client system sends the
request to the Server system and the Server system processes the request and sends
back the data to the Client System
Three-tier architecture :is divided into three parts:
1. Presentation layer (Client Tier)
2. Application layer (Business Tier)
3. Database layer (Data Tier)
Database Models:
A Database model defines the logical design and structure of a database and
defines how data will be stored, accessed and updated in a database
management system.
While the Relational Model is the most widely used database model,
2)The data model should be detailed enough to be used for building the
physical database.
3)The information in the data model can be used for defining the
relationship between tables, primary and foreign keys, and stored
procedures.
The hierarchy starts from the Root data, and expands like a tree, adding child
nodes to the parent nodes.
In this model, a child node will only have a single parent node.
Network Model
relationships are created by dividing object of interest into entity and its characteristics
into attributes.
E-R Models are defined to represent the relationships into pictorial form to
make it easier for different stakeholders to understand.
Relational Model
Data is organised in two-dimensional tables and the relationship is maintained by
storing a common field.
This model was introduced by E.F Codd in 1970, and since then it has been the
most widely used database model, infact, we can say the only database model
used around the world.
The basic structure of data in the relational model is tables. All the information
related to a particular type is stored in rows of that table.
Describes the structure of a database with the help of a diagram, which is known
as Entity Relationship Diagram (ER Diagram). An ER model is a design or blueprint of a
database that can later be implemented as a database.
Student
Weak Entity:
An entity that cannot be uniquely identified by its own attributes and relies on the
relationship with other entity is called weak entity. The weak entity is represented
by a double rectangle. For example – a bank account cannot be uniquely identified
without knowing the bank to which the account belongs, so bank account is a weak
entity.
Attribute(s):
Attributes are the properties which define the entity type. For example, Roll_No,
Name, DOB, Age, Address, Mobile_No are the attributes which defines entity type
Student. In ER diagram, attribute is represented by an oval.
1)Key Attribute –
The attribute which uniquely identifies each entity in the entity set is called key
attribute.For example, Roll_No will be unique for each student. In ER diagram, key attribute
is represented by an oval with underlying lines.
Composite Attribute –
An attribute composed of many other attribute is called as composite attribute. For
example, Address attribute of student Entity type consists of Street, City, State, and
Country. In ER diagram, composite attribute is represented by an oval comprising of
ovals.
Multivalued Attribute –
An attribute consisting more than one value for a given entity. For example,
Phone_No (can be more than one for a given student). In ER diagram, multivalued
attribute is represented by double oval.
Derived Attribute –
An attribute which can be derived from other attributes of the entity type is known
as derived attribute. e.g.; Age (can be derived from DOB). In ER diagram, derived
attribute is represented by dashed oval.
The complete entity type Student with its attributes can be represented as:
Relationship:
Relationship Set
A set of relationships of similar type is called a relationship set. Like entities, a
relationship too can have attributes. These attributes are called descriptive
attributes.
Degree of Relationship
The number of participating entities in a relationship defines the degree of
the relationship.
1)Binary = degree 2
2)Ternary = degree 3
3)n-ary = degree
Mapping Cardinalities:
Cardinality defines the number of entities in one entity set, which can be
associated with the number of entities of other set via relationship set.
One-to-one − One entity from entity set A can be associated with at most one
entity of entity set B and vice versa.
One-to-many −:
One entity from entity set A can be associated with more than one entities of
entity set B however an entity from entity set B, can be associated with at most
one entity.
Many-to-many :
One entity from A can be associated with more than one entity from B
and vice versa.
Relationship
Relationships are represented by diamond-shaped box. Name of the relationship is written
inside the diamond-box. All the entities (rectangles) participating in a relationship, are
connected to it by a line.
One-to-one − When only one instance of an entity is associated with the relationship, it is
marked as '1:1'. The following image reflects that only one instance of each entity should be
associated with the relationship. It depicts one-to-one relationship.
One-to-many −:
When more than one instance of an entity is associated with a relationship, it is marked
as '1:N'. The following image reflects that only one instance of entity on the left and
more than one instance of an entity on the right can be associated with the relationship.
It depicts one-to-many relationship.
Many-to-many −:
The following image reflects that more than one instance of an entity on the left and
more than one instance of an entity on the right can be associated with the relationship.
It depicts many-to-many relationship.
Participation Constraints:
Partial participation − Not all entities are involved in the relationship. Partial
participation is represented by single lines.
Keys: Keys play an important role in the relational database.
It is used to uniquely identify any record or row of data from the table. It is also
used to establish and identify relationships between tables.
Types of key:
1) Primary key:
It is the first key which is used to identify one and only one instance of an
entity uniquely. An entity can contain multiple keys as we saw in PERSON
table. The key which is most suitable from those lists become a primary
key.
2. Candidate key:
A candidate key is an attribute or set of an attribute which can uniquely
identify a tuple.
The remaining attributes except for primary key are considered as a candidate
key. The candidate keys are as strong as the primary key.
3. Super Key
Super key is a set of an attribute which can uniquely identify a tuple. Super key is a
superset of a candidate key.
4.Foreign key:
•Foreign keys are the column of the table which is used to point to the primary key of another table.
•In a company, every employee works in a specific department, and employee and department are two
different entities. So we can't store the information of the department in the employee table. That's
why we link these two tables through the primary key of one table.
•We add the primary key of the DEPARTMENT table, Department_Id as a new attribute in the
EMPLOYEE table.
•Now in the EMPLOYEE table, Department_Id is the foreign key, and both the tables are related.
Dr Edgar F. Codd, after his extensive research on the Relational Model of database
systems, came up with twelve rules of his own, which according to him, a database
must obey in order to be regarded as a true relational database.
These rules can be applied on any database system that manages stored data using
only its relational capabilities. This is a foundation rule, which acts as a base for all the
other rules.
1)Specialization
2)Generalization
3)Aggregation
Generalization
Generalization is like a bottom-up approach in which two or more entities of lower level
combine to form a higher level entity if they have some attributes in common.
In generalization, an entity of a higher level can also combine with the entities of the lower
level to form a further higher level entity.
Generalization is more like subclass and superclass system, but the only difference is the
approach. Generalization uses the bottom-up approach.
In generalization, entities are combined to form a more generalized entity, i.e., subclasses are
combined to make a superclass.
Specialization
Specialization is a top-down approach, and it is opposite to Generalization. In
specialization, one higher level entity can be broken down into two lower level
entities.
Specialization is used to identify the subset of an entity set that shares some
distinguishing characteristics.
Normally, the super class is defined first, the subclass and its related attributes are
defined next, and relationship set are then added.
Aggregation
In aggregation, the relation between two entities is treated as a single entity. In
aggregation, relationship with its corresponding entities is aggregated into a higher level
entity.
Reduction of ER diagram to Table
Entity type becomes a table.
In the given ER diagram, LECTURE, STUDENT, SUBJECT and COURSE forms individual tables.
Book: Book id,Price, Title, ISBN NO., Author, Publication, Available or Not.
Publication: Year,Name,id.
X → Y
The left side of FD is known as a determinant, the right side of the production is
known as a dependent.
3)Normalization divides the larger table into the smaller table and links them using
relationship.
4)The normal form is used to reduce redundancy from the database table.
Types of Normal Forms:
2NF A relation will be in 2NF if it is in 1NF and all non-key attributes are
fully functional dependent on the primary key.
It states that an attribute of a table cannot hold multiple values. It must hold only
single-valued attribute.
First normal form disallows the multi-valued attribute, composite attribute, and their
combinations.
Employee table:
EMP_ID EMP_NAME EMP_PHONE EMP_STATE
14 John 7272826385, UP
9064738238
20 Harry 8574783832 Bihar
12 Sam 7390372389, Punjab
8589830302
The decomposition of the EMPLOYEE table into 1NF has been shown below:
14 John 7272826385 UP
14 John 9064738238 UP
20 Harry 8574783832 Bihar
12 Sam 7390372389 Punjab
12 Sam 8589830302 Punjab
Second Normal Form (2NF)
In the 2NF, relational must be in 1NF.
In the second normal form, all non-key attributes are fully functional dependent on the
primary key
The set of all those attributes which can be functionally determined from an
attribute set is called as a closure of that attribute set.
A+ = { A } D+ = { D }
={A,B,C} ( Using A → BC ) = { D , F } ( Using D → F )
={A,B,C,D,E} ( Using BC → DE ) We can not determine any other attribute using
={A,B,C,D,E,F} ( Using D → F ) attributes D and F contained in the result set.
= { A , B , C , D , E , F , G } ( Using CF → G ) Thus,
Thus, D+ = { D , F }
A+ = { A , B , C , D , E , F , G }
{ B , C } += { B , C }
={B,C,D,E} ( Using BC → DE )
={B,C,D,E,F} ( Using D → F )
= { B , C , D , E , F , G } ( Using CF → G )
Thus,
{ B , C }+ = { B , C , D , E , F , G }
Example
R= {A, B, C, D}
FD = {A→B, B→C, C→D}
Example
Let suppose R= {A, B, C, D} and FD = {A→B, B→C, C→D, D→A}
Closure of attribute “A”
According to the recursive rule, Attribute “A” can determine Attribute “A” itself.
According to the given FD, Attribute “A” can directly determine Attribute “B”.
According to the transitive property, Attribute “A” can determine “C” through “B.”
According to the transitive property, As Attribute “A” already determines C, Attribute “A” can
determine “D” through “C.”
So, Closure of A = A+ = ABCD
Closure of attribute “B”
According to the recursive rule, Attribute “B” can determine Attribute “B” itself.
According to the given FD, Attribute “B” can directly determine Attribute “C”.
According to the transitive property, Attribute “B” can determine “D” through “C”.
Attribute “B” cannot determine attribute “A”
So, Closure of B = B+ = BCD
Closure of attribute “C”
According to the recursive rule, Attribute “C” can determine Attribute “C” itself.
According to the given FD, Attribute “C” can directly determine Attribute “D.”
Attribute “C” cannot determine attributes “A” and “B”
So, Closure of C = C+ = CD
Closure of attribute “D”
According to the recursive rule, Attribute “D” can determine Attribute “C” itself.
Attribute “D” cannot determine attributes “A,” “B,” and “C.”
So, Closure of D = D+ = D
Conclusion: As we see, only the closure of attribute “A” can determine all attributes of the
relation, so attribute “A” can be used as the Candidate key.
So, Candidate Key = {A}
Closure of attribute “A”
As Attribute “A” can determine itself.
According to FD, Attribute “A” can directly determine Attribute “B”.
According to the transitive property, Attribute “A” can determine “C” through “B”.
According to the transitive property, As Attribute “A” already determines C, Attribute “A” can determine “D” through
“C”.
So, Closure of A = A+ = ABCD
Closure of attribute “B”
As Attribute “B” can determine itself.
According to FD, Attribute “B” can directly determine Attribute “C”.
According to the transitive property, Attribute “B” can determine “D” through “C”.
According to the transitive property, As Attribute “B” already determines D, Attribute “B” can determine “A” through
“D”.
So, Closure of B = B+ = BCDA
Closure of attribute “C”
As Attribute “C” can determine itself.
According to FD, Attribute “C” can directly determine Attribute “D.”
According to the transitive property, As Attribute “C” already determines D, Attribute “C” can determine “A” through
“D”.
As Attribute “C” already determines A So, Attribute “C” can determine “B” through “A”.
So, Closure of C = C+ = CDAB
Closure of attribute “D”
As Attribute “D” can determine itself.
According to FD, Attribute “D” can directly determine Attribute “A.”
According to transitive property, As Attribute “D” already determines A, Attribute “D” can determine “B” through “A”.
As Attribute “D” already determines B, Attribute “D” can determine “C” through “B”.
So, Closure of D = D+ = DABC
Conclusion: As we see, the closure of all attributes, “A,” “B,” “C,” and “D,” can determine all attributes of relation so
all attributes can be used as Candidate keys.
So, Candidate Key = {A, B, C, D}
Example: Let's assume, a school can store the data of teachers and the subjects they teach. In a school, a
teacher can teach more than one subject.
TEACHER table
TEACHER_ID SUBJECT TEACHER_AGE
25 Chemistry 30
25 Biology 30
47 English 35
83 Math 38
83 Computer 38
To convert the given table into 2NF, we decompose it into two tables:
TEACHER_DETAIL table:
TEACHER_SUBJECT table
TEACHER_DETAIL table:
TEACHER_ID TEACHER_AGE
25 30
47 35
83 38
TEACHER_SUBJECT table:
TEACHER_ID SUBJECT
25 Chemistry
25 Biology
47 English
83 Math
83 Computer
Third Normal Form (3NF)
•A relation will be in 3NF if it is in 2NF and not contain any transitive partial dependency.
•3NF is used to reduce the data duplication. It is also used to achieve the data integrity.
•If there is no transitive dependency for non-prime attributes, then the relation must be in
third normal form.
•A relation is in third normal form if it holds atleast one of the following conditions for every
non-trivial function dependency X → Y.
•X is a super key.
Non-prime attributes: In the given table, all attributes except EMP_ID are non-prime.
Here, EMP_STATE & EMP_CITY dependent on EMP_ZIP and EMP_ZIP dependent on
EMP_ID. The non-prime attributes (EMP_STATE, EMP_CITY) transitively dependent on
super key(EMP_ID). It violates the rule of third normal form.
That's why we need to move the EMP_CITY and EMP_STATE to the new
<EMPLOYEE_ZIP> table, with EMP_ZIP as a Primary key.
EMPLOYEE table:
EMPLOYEE_ZIP table:
201010 UP Noida
02228 US Boston
60007 US Chicago
06389 UK Norwich
462007 MP Bhopal
Boyce Codd normal form (BCNF)
•BCNF is the advance version of 3NF. It is stricter than 3NF.
•A table is in BCNF if every functional dependency X → Y, X is the super key of the
table.
•For BCNF, the table should be in 3NF, and for every FD, LHS is super key.
Example: Let's assume there is a company where employees work in more than one
department.
EMP_ID EMP_COUNTRY
264 India
264 India
EMP_DEPT table:
EMP_DEPT_MAPPING table:
EMP_ID EMP_DEPT
D394 283
D394 300
D283 232
D283 549
Functional dependencies:
EMP_ID → EMP_COUNTRY
EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
Candidate keys:
For the first table: EMP_ID
For the second table: EMP_DEPT
For the third table: {EMP_ID, EMP_DEPT}
Now, this is in BCNF because left side part of both the functional dependencies is
a key.
4:Relational Algebra :
Relational Algebra:
Relational algebra is a procedural query language, which takes instances of relations as
input and yields instances of relations as output. It uses operators to perform queries.
An operator can be either unary or binary. They accept relations as their input and
yield relations as their output. Relational algebra is performed recursively on a relation
and intermediate results are also considered relations.
Notation: σ p(r)
Where:
σ is used for selection prediction
r is used for relation
p is used as a propositional logic formula which may use connectors like: AND
OR and NOT. These relational can use as relational operators like =, ≠, ≥, <, >, ≤.
For
example −
σsubject = "database"(Books)
Output − Selects tuples from books where subject is 'database' and 'price' is
450.
Output − Selects tuples from books where subject is 'database' and 'price'
is 450 or those books published after 2010.
Select Operation: Notation: σ p(r)
Input:
σ BRANCH_NAME="perryride" (LOAN)
Output:
For example,
∏Name, Age(Student)
Above statement will show us only the Name and Age columns for all the
rows of data in Student table.
2. Project Operation: Notation: ∏ A1, A2, An (r)
Output:
NAME CITY
Jones Harrison
Smith Rye
Hays Harrison
Curry Rye
Johnson Brooklyn
Brooks Brooklyn
Union Operation:
Suppose there are two tuples R and S. The union operation contains all the tuples
that are either in R or S or both in R & S.
It eliminates the duplicate tuples. It is denoted by ∪.
Notation: R ∪ S
A union operation must hold the following condition:
R and S must have the attribute of the same number.
Duplicate tuples are eliminated automatically.
DEPOSITOR RELATION CUSTOMER_NAME ACCOUNT_NO
Johnson A-101
Smith A-121
Mayes A-321
Turner A-176
Johnson A-273
Jones A-472
Lindsay A-284
BORROW RELATION
CUSTOMER_NAME LOAN_NO
Jones L-17
Smith L-23
Hayes L-15
Jackson L-14
Curry L-93
Smith L-11
Williams L-17
∏ CUSTOMER_NAME (BORROW) ∪ ∏ CUSTOMER_NAME (DEPOSITOR)
Input:
Output: CUSTOMER_NAME
Johnson
Smith
Hayes
Turner
Jones
Lindsay
Jackson
Curry
Williams
Mayes
Set Intersection:
Suppose there are two tuples R and S. The set intersection operation contains all tuples
that are in both R & S.
It is denoted by intersection ∩.
Notation: R ∩ S
Output:
CUSTOMER_NAME
Smith
Jones
Set Difference:
Suppose there are two tuples R and S. The set intersection operation contains all
tuples that are in R but not in S.
It is denoted by intersection minus (-).
Notation: R - S
Output: CUSTOMER_NAME
Jackson
Hayes
Willians
Curry
Cartesian product
The Cartesian product is used to combine each row in one table with each row in
the other table. It is also known as a cross product.
It is denoted by X.
Example:
EMPLOYEE
EMP_ID EMP_NAME EMP_DEPT
1 Smith A
2 Harry C
3 John B
DEPARTMENT
DEPT_NO DEPT_NAME
A Marketing
B Sales
C Legal
1 Smith A A Marketing
1 Smith A B Sales
1 Smith A C Legal
2 Harry C A Marketing
2 Harry C B Sales
2 Harry C C Legal
3 John B A Marketing
3 John B B Sales
3 John B C Legal
Join Operations:
A Join operation combines related tuples from different relations, if and only if a given
join condition is satisfied.
It is denoted by ⋈.
101 50000
102 30000
103 25000
It is denoted by ⋈.
Example: Let's use the above EMPLOYEE table and SALARY table:
Input:
∏EMP_NAME, SALARY (EMPLOYEE ⋈ SALARY)
Output:
EMP_NAME SALARY
Stephan 50000
Jack 30000
Harry 25000
2. Outer Join:
The outer join operation is an extension of the join operation. It is used to deal with
missing information.
Example:
EMPLOYEE
FACT_WORKERS
Output:
Input:
1.EMPLOYEE ⟕ FACT_WORKERS
•It is denoted by ⟖.
Input:
1.EMPLOYEE ⟖ FACT_WORKERS
Output:
It is denoted by ⟗.
Input:
EMPLOYEE ⟗ FACT_WORKERS
Output:
CUSTOMER RELATION
CLASS_ID NAME
1 John
2 Harry
3 Jackson
PRODUCT
PRODUCT_ID CITY
1 Delhi
2 Mumbai
3 Noida
Input:
CUSTOMER ⋈ PRODUCT
1 John 1 Delhi
2 Harry 2 Mumbai
3 Harry 3 Noida
Find right outer join ,left outer join and full join from following table?
Table A
Number Square
2 4
3 9
4 16
Table B
Number Cube
2 8
3 27
5 75
Left Outer Join Number Square Cube
2 4 8
A⟕B
3 9 27
4 16 –
A⟖B 3 9 27
5 – 75
2 4 8
3 9 27
Full Outer Join
4 16 –
A⟗B
5 – 75
Relational Calculus:
The relational calculus tells what to do but never explains how to do.
The tuple relational calculus is specified to select the tuples in a relation. In TRC, filtering
variable uses the tuples of a relation.
Notation:
{T | P (T)} or {T | Condition (T)}
Where
T is the resulting tuples
OUTPUT: This query selects the tuples from the AUTHOR relation. It returns a tuple with
'name' from Author who has written an article on 'database'.
TRC (tuple relation calculus) can be quantified. In TRC, we can use Existential (∃) and
Universal Quantifiers (∀).
For example:
Output: This query will yield the same result as the previous one.
2. Domain Relational Calculus (DRC)
The second form of relation is known as Domain relational calculus. In domain relational
calculus, filtering variable uses the domain of attributes.
Domain relational calculus uses the same operators as tuple calculus. It uses logical
connectives ∧ (and), ∨ (or) and ┓ (not).
It uses Existential (∃) and Universal Quantifiers (∀) to bind the variable.
Notation:
Where
a1, a2 are attributes
Output: This query will yield the article, page, and subject from the relational
javatpoint, where the subject is a database.
Example2:
above query will return the names and ages of the students in the table Student who are older than. 17
Example 3
The result here will be returning the Fname and Emp_ID values for all the rows in the employee table where salary is greater than 10000
or department is 10.