SlideShare a Scribd company logo
1 of 44
RELATIONAL
ALGEBRA
DBMS UNIT II
Relational Algebra
■ Relational algebra is a
procedural query language. It
gives a step by step process
to obtain the result of the
query. It uses operators to
perform queries.
1. Select Operation
■ The select operation selects tuples that satisfy a given predicate.
■ It is denoted by sigma (σ).
■ 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 =, ≠, ≥, <, >, ≤.
EXAMPLE
BRANCH_NAME LOAN_NO AMOUNT
Downtown L-17 1000
Redwood L-23 2000
Perryride L-15 1500
Downtown L-14 1500
Mianus L-13 500
Roundhill L-11 900
Perryride L-16 1300
or example: LOAN Relation
Input:
■ σ BRANCH_NAME="perryride" (LOAN)
BRANCH_NAME LOAN_NO AMOUNT
Perryride L-15 1500
Perryride L-16 1300
OUTPUT
2. Project Operation
■ This operation shows the list of those attributes that we wish to appear in the result.
Rest of the attributes are eliminated from the table.
■ It is denoted by ∏.
■ Notation: ∏ A1, A2, An (r)
■ Where
■ A1, A2, A3 is used as an attribute name of relation r.
2. Project Operation
NAME STREET CITY
Jones Main Harrison
Smith North Rye
Hays Main Harrison
Curry North Rye
Johnson Alma Brooklyn
Brooks Senator Brooklyn
EXAMPLE
CUSTOMER RELATION
■ Input:
■ ∏ NAME, CITY (CUSTOMER)
NAME CITY
Jones Harrison
Smith Rye
Hays Harrison
Curry Rye
Johnson Brooklyn
Brooks Brooklyn
Output:
3. 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.
Example:
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
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
BORROW RELATION
■ Input: ∏ CUSTOMER_NAME (BORROW) ∪ ∏ CUSTOMER_NAME (DEPOSITOR)
CUSTOMER_NAME
Johnson
Smith
Hayes
Turner
Jones
Lindsay
Jackson
Curry
Williams
Mayes
Output:
4. 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
Example: Using the above DEPOSITOR table and BORROW table
4. Set Intersection:
■ Input: ∏ CUSTOMER_NAME (BORROW) ∩ ∏ CUSTOMER_NAME (DEPOSITOR)
■ Output
CUSTOMER_NAME
Smith
Jones
5. 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
■ Example: Using the above DEPOSITOR table and BORROW table
■ Input: ∏ CUSTOMER_NAME (BORROW) - ∏ CUSTOMER_NAME (DEPOSITOR)
■
CUSTOMER_NAME
Jackson
Hayes
Willians
Curry
Output:
6. 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.
■ Notation: E X D
EMP_ID EMP_NAME EMP_DEPT
1 Smith A
2 Harry C
3 John B
Example:
EMPLOYEE
DEPT_NO DEPT_NAME
A Marketing
B Sales
C Legal
DEPARTMENT
■ Input:
■ EMPLOYEEX DEPARTMENT
EMP_ID EMP_NAME EMP_DEPT DEPT_NO DEPT_NAME
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
Output:
7. Rename Operation:
■ The rename operation is used to rename the output relation. It is denoted by rho (ρ).
■ Example:We can use the rename operator to rename STUDENT relation to
STUDENT1.
■ ρ(STUDENT1, STUDENT)
RDBMS:What isTable ?
■ In Relational database model, a table is a collection of data elements organised in
terms of rows and columns.A table is also considered as a convenient representation
of relations. But a table can have duplicate row of data while a true relation cannot
have duplicate data.Table is the most simplest form of data storage. Below is an
example of an Employee table.
ID Name Age Salary
1 Adam 34 13000
2 Alex 28 15000
3 Stuart 20 18000
4 Ross 42 19020
RDBMS:What is aTuple?
■ A single entry in a table is called a Tuple or Record or Row.A tuple in a table
represents a set of related data. For example, the above Employee table has 4
tuples/records/rows.
■ Following is an example of single record or tuple.
■
1 Adam 34 13000
RDBMS:What is an Attribute?
■ A table consists of several records(row), each record can be broken down
into several smaller parts of data known as Attributes. The
above Employee table consist of four attributes, ID, Name, Age and Salary
■ Attribute Domain
– When an attribute is defined in a relation(table), it is defined to hold only
a certain type of values, which is known as Attribute Domain.
– Hence, the attribute Name will hold the name of employee for every
tuple. If we save employee's address there, it will be violation of the
Relational database model.
Name
Adam
Alex
Stuart - 9/401, OC
Street, Amsterdam
Ross
Cardinality (Degree of Relationship)
■ The degree of relationship can be defined as the number of occurrences in one entity
that is associated with the number of occurrences in another entity.
■ There is the three degree of relationship:
■ One-to-one (1:1)
■ One-to-many (1:M)
■ Many-to-many (M:N)
1. One-to-one
■ In a one-to-one relationship, one occurrence of an entity relates to only one
occurrence in another entity.
■ A one-to-one relationship rarely exists in practice.
■ For example: if an employee is allocated a company car then that car can only be
driven by that employee.
■ Therefore, employee and company car have a one-to-one relationship.
2. One-to-many
■ In a one-to-many relationship, one occurrence in an entity relates to many occurrences
in another entity.
■ For example:An employee works in one department, but a department has many
employees.
■ Therefore, department and employee have a one-to-many relationship.
3. Many-to-many
■ In a many-to-many relationship, many occurrences in an entity relate to many
occurrences in another entity.
■ Same as a one-to-one relationship, the many-to-many relationship rarely exists in
practice.
■ For example: At the same time, an employee can work on several projects, and a
project has a team of many employees.
■ Therefore, employee and project have a many-to-many relationship.
Degree of Relationship
The number of participating entities in a relationship defines the degree of the
relationship.
■ Unary
■ Binary = degree 2
■ Ternary = degree 3
■ n-ary = degree
Unary (degree 1)
■ A unary relationship exists when both the participating entity type are the same.
When such a relationship is present we say that the degree of relationship is 1.
■ For example, Suppose in a classroom, we have many students who belong to a
particular club-like dance club, basketball club etc. and some of them are club leads.
So, a particular group of student is managed by their respective club lead. Here, the
group is formed from students and also, the club leads are chosen from students. So,
the ‘Student’ is the only entity participating here. We can represent this relationship
using the E-R diagram as follows:
Binary (degree 2)
■ A binary relationship exists when exactly two entity type participates.When such a
relationship is present we say that the degree is 2.This is the most common degree of
relationship. It is easy to deal with such relationship as these can be easily converted
into relational tables.
■ For example,We have two entity type ‘Customer’ and ‘Account’ where each
‘Customer’ has an ‘Account’ which stores the account details of the ‘Customer’. Since
we have two entity types participating we call it a binary relationship.Also, one
‘Customer’ can have many ‘Account’ but each ‘Account’ should belong to only one
‘Customer’.We can say that it is a one-to-many binary relationship.
Ternary(degree 3)
■ A ternary relationship exists when exactly three entity type participates.When such a
relationship is present we say that the degree is 3. As the number of entity increases in
the relationship, it becomes complex to convert them into relational tables.
■ For example,We have three entity type ‘Employee’, ‘Department’ and ‘Location’.The
relationship between these entities are defined as an employee works in a
department, an employee works at a particular location. So, we can see we have three
entities participating in a relationship so it is a ternary relationship.The degree of this
relation is 3.
N-ary (n degree)
■ An N-ary relationship exists when ‘n’ number of entities are participating. So, any
number of entities can participate in a relationship.There is no limitation to the
maximum number of entities that can participate.
N
Integrity Constraints
■ Integrity constraints are a set of rules. It is used to maintain the quality of information.
■ Integrity constraints ensure that the data insertion, updating, and other processes
have to be performed in such a way that data integrity is not affected.
■ Thus, integrity constraint is used to guard against accidental damage to the database.
Types of Integrity Constraint
1. Domain constraints
■ Domain constraints can be defined as the definition of a valid set of values for an
attribute.
■ The data type of domain includes string, character, integer, time, date, currency, etc.
The value of the attribute must be available in the corresponding domain.
2. Entity integrity constraints
■ The entity integrity constraint states that primary key value can't be null.
■ This is because the primary key value is used to identify individual rows in relation and
if the primary key has a null value, then we can't identify those rows.
■ A table can contain a null value other than the primary key field.
3. Referential Integrity Constraints
■ A referential integrity constraint is specified between two tables.
■ In the Referential integrity constraints, if a foreign key inTable 1 refers to the Primary
Key ofTable 2, then every value of the Foreign Key inTable 1 must be null or be
available inTable 2.
4. Key constraints
■ Keys are the entity set that is used to identify an entity within its entity set uniquely.
■ An entity set can have multiple keys, but out of which one key will be the primary key.
A primary key can contain a unique and null value in the relational table.
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.
■ For example: In Student table, ID is used as a key because it is unique for each
student. In PERSON table, passport_number, license_number, SSN are keys since they
are unique for each person.
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.
■ In the EMPLOYEE table, ID can be primary key since it is unique for each employee. In
the EMPLOYEE table, we can even select License_Number and Passport_Number as
primary key since they are also unique.
■ For each entity, selection of the primary key is based on requirement and developers.
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.
■ For example: In the EMPLOYEE table, id is best suited for the primary key. Rest of the
attributes like SSN, Passport_Number, and License_Number, etc. are considered as a
candidate 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.
■ For example: In the above EMPLOYEE table, for(EMPLOEE_ID, EMPLOYEE_NAME)
the name of two employees can be the same, but their EMPLYEE_ID can't be the
same. Hence, this combination can also be a key.
■ The super key would be EMPLOYEE-ID, (EMPLOYEE_ID, EMPLOYEE-NAME), etc.
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.
4. Foreign key

More Related Content

What's hot

All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbms
Naresh Kumar
 
Record storage and primary file organization
Record storage and primary file organizationRecord storage and primary file organization
Record storage and primary file organization
Jafar Nesargi
 

What's hot (20)

Dbms 4NF & 5NF
Dbms 4NF & 5NFDbms 4NF & 5NF
Dbms 4NF & 5NF
 
ER Model in DBMS
ER Model in DBMSER Model in DBMS
ER Model in DBMS
 
Object oriented database concepts
Object oriented database conceptsObject oriented database concepts
Object oriented database concepts
 
Relational model
Relational modelRelational model
Relational model
 
Normalization
NormalizationNormalization
Normalization
 
Entity Relationship Diagrams
Entity Relationship DiagramsEntity Relationship Diagrams
Entity Relationship Diagrams
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
Relational algebra.pptx
Relational algebra.pptxRelational algebra.pptx
Relational algebra.pptx
 
Difference between File system And DBMS.pptx
Difference between File system And DBMS.pptxDifference between File system And DBMS.pptx
Difference between File system And DBMS.pptx
 
Introduction to Database Management System
Introduction to Database Management SystemIntroduction to Database Management System
Introduction to Database Management System
 
Ram presentation
Ram presentationRam presentation
Ram presentation
 
All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbms
 
Introduction to Database
Introduction to DatabaseIntroduction to Database
Introduction to Database
 
ER MODEL
ER MODELER MODEL
ER MODEL
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
 
Indexing structure for files
Indexing structure for filesIndexing structure for files
Indexing structure for files
 
Data Base System Application - Unit 7
Data Base System Application - Unit 7Data Base System Application - Unit 7
Data Base System Application - Unit 7
 
Unit1 DBMS Introduction
Unit1 DBMS IntroductionUnit1 DBMS Introduction
Unit1 DBMS Introduction
 
Record storage and primary file organization
Record storage and primary file organizationRecord storage and primary file organization
Record storage and primary file organization
 

Similar to Dbms unit ii

1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf
Kavinilaa
 
Relational Database design.pptx
Relational Database design.pptxRelational Database design.pptx
Relational Database design.pptx
johndoe193402
 
3. Relational Models in DBMS
3. Relational Models in DBMS3. Relational Models in DBMS
3. Relational Models in DBMS
koolkampus
 

Similar to Dbms unit ii (20)

Unit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operationUnit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operation
 
Relational model
Relational modelRelational model
Relational model
 
Relational algebra operations
Relational algebra operationsRelational algebra operations
Relational algebra operations
 
Data Base Managment system
Data Base Managment systemData Base Managment system
Data Base Managment system
 
Data base managment system
Data base managment system Data base managment system
Data base managment system
 
1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf
 
Relational Database design.pptx
Relational Database design.pptxRelational Database design.pptx
Relational Database design.pptx
 
UNIT 2 -PPT.pptx
UNIT 2 -PPT.pptxUNIT 2 -PPT.pptx
UNIT 2 -PPT.pptx
 
3.ppt
3.ppt3.ppt
3.ppt
 
Lllll
LllllLllll
Lllll
 
3. Relational Models in DBMS
3. Relational Models in DBMS3. Relational Models in DBMS
3. Relational Models in DBMS
 
Relation model part 1
Relation model part 1Relation model part 1
Relation model part 1
 
relational model in Database Management.ppt.ppt
relational model in Database Management.ppt.pptrelational model in Database Management.ppt.ppt
relational model in Database Management.ppt.ppt
 
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
 
Lec02
Lec02Lec02
Lec02
 
Unit04 dbms
Unit04 dbmsUnit04 dbms
Unit04 dbms
 
Relational model
Relational modelRelational model
Relational model
 
Desigining of Database - ER Model
Desigining of Database - ER ModelDesigining of Database - ER Model
Desigining of Database - ER Model
 
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY  MILAN PATELCHAPTER 2 DBMS IN EASY WAY BY  MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
 
Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational model
 

More from Arnav Chowdhury

More from Arnav Chowdhury (20)

Startup Funding and Strategies for Future
Startup Funding and Strategies for FutureStartup Funding and Strategies for Future
Startup Funding and Strategies for Future
 
Marketing Management Introduction.pptx
Marketing Management Introduction.pptxMarketing Management Introduction.pptx
Marketing Management Introduction.pptx
 
Marketing Management Product.pptx
Marketing Management Product.pptxMarketing Management Product.pptx
Marketing Management Product.pptx
 
Institutional Support to Entrepreneurship
Institutional Support to EntrepreneurshipInstitutional Support to Entrepreneurship
Institutional Support to Entrepreneurship
 
New Venture Expansion and Exit Strategies
New Venture Expansion and Exit StrategiesNew Venture Expansion and Exit Strategies
New Venture Expansion and Exit Strategies
 
Creating a Business Plan
Creating a Business PlanCreating a Business Plan
Creating a Business Plan
 
Business Research Methodology ( Data Collection)
Business Research Methodology ( Data Collection)Business Research Methodology ( Data Collection)
Business Research Methodology ( Data Collection)
 
Business Research Methods (Introduction)
Business Research Methods (Introduction)Business Research Methods (Introduction)
Business Research Methods (Introduction)
 
Planning and organizing Entrepreneurial Venture
Planning and organizing Entrepreneurial VenturePlanning and organizing Entrepreneurial Venture
Planning and organizing Entrepreneurial Venture
 
Fundamentals of Entrepreneurship
Fundamentals of EntrepreneurshipFundamentals of Entrepreneurship
Fundamentals of Entrepreneurship
 
ICT tools in Education
ICT tools in EducationICT tools in Education
ICT tools in Education
 
Unit v: Cyber Safety Mechanism
Unit v: Cyber Safety MechanismUnit v: Cyber Safety Mechanism
Unit v: Cyber Safety Mechanism
 
UNIT IV:Security Measurement Strategies
UNIT IV:Security Measurement StrategiesUNIT IV:Security Measurement Strategies
UNIT IV:Security Measurement Strategies
 
Unit iii: Common Hacking Techniques
Unit iii: Common Hacking TechniquesUnit iii: Common Hacking Techniques
Unit iii: Common Hacking Techniques
 
Cyber Crime
Cyber CrimeCyber Crime
Cyber Crime
 
Information Technology and Modern Gadgets
Information Technology and Modern GadgetsInformation Technology and Modern Gadgets
Information Technology and Modern Gadgets
 
Unit iv FMIS
Unit iv FMISUnit iv FMIS
Unit iv FMIS
 
Unit iii FMIS
Unit iii FMISUnit iii FMIS
Unit iii FMIS
 
Unit ii FMIS
Unit ii FMISUnit ii FMIS
Unit ii FMIS
 
Unit iv graphics
Unit iv  graphicsUnit iv  graphics
Unit iv graphics
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

Dbms unit ii

  • 2. Relational Algebra ■ Relational algebra is a procedural query language. It gives a step by step process to obtain the result of the query. It uses operators to perform queries.
  • 3. 1. Select Operation ■ The select operation selects tuples that satisfy a given predicate. ■ It is denoted by sigma (σ). ■ 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 =, ≠, ≥, <, >, ≤.
  • 4. EXAMPLE BRANCH_NAME LOAN_NO AMOUNT Downtown L-17 1000 Redwood L-23 2000 Perryride L-15 1500 Downtown L-14 1500 Mianus L-13 500 Roundhill L-11 900 Perryride L-16 1300 or example: LOAN Relation
  • 5. Input: ■ σ BRANCH_NAME="perryride" (LOAN) BRANCH_NAME LOAN_NO AMOUNT Perryride L-15 1500 Perryride L-16 1300 OUTPUT
  • 6. 2. Project Operation ■ This operation shows the list of those attributes that we wish to appear in the result. Rest of the attributes are eliminated from the table. ■ It is denoted by ∏. ■ Notation: ∏ A1, A2, An (r) ■ Where ■ A1, A2, A3 is used as an attribute name of relation r.
  • 7. 2. Project Operation NAME STREET CITY Jones Main Harrison Smith North Rye Hays Main Harrison Curry North Rye Johnson Alma Brooklyn Brooks Senator Brooklyn EXAMPLE CUSTOMER RELATION
  • 8. ■ Input: ■ ∏ NAME, CITY (CUSTOMER) NAME CITY Jones Harrison Smith Rye Hays Harrison Curry Rye Johnson Brooklyn Brooks Brooklyn Output:
  • 9. 3. 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.
  • 10. Example: 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 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 BORROW RELATION
  • 11. ■ Input: ∏ CUSTOMER_NAME (BORROW) ∪ ∏ CUSTOMER_NAME (DEPOSITOR) CUSTOMER_NAME Johnson Smith Hayes Turner Jones Lindsay Jackson Curry Williams Mayes Output:
  • 12. 4. 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 Example: Using the above DEPOSITOR table and BORROW table
  • 13. 4. Set Intersection: ■ Input: ∏ CUSTOMER_NAME (BORROW) ∩ ∏ CUSTOMER_NAME (DEPOSITOR) ■ Output CUSTOMER_NAME Smith Jones
  • 14. 5. 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
  • 15. ■ Example: Using the above DEPOSITOR table and BORROW table ■ Input: ∏ CUSTOMER_NAME (BORROW) - ∏ CUSTOMER_NAME (DEPOSITOR) ■ CUSTOMER_NAME Jackson Hayes Willians Curry Output:
  • 16. 6. 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. ■ Notation: E X D
  • 17. EMP_ID EMP_NAME EMP_DEPT 1 Smith A 2 Harry C 3 John B Example: EMPLOYEE DEPT_NO DEPT_NAME A Marketing B Sales C Legal DEPARTMENT
  • 18. ■ Input: ■ EMPLOYEEX DEPARTMENT EMP_ID EMP_NAME EMP_DEPT DEPT_NO DEPT_NAME 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 Output:
  • 19. 7. Rename Operation: ■ The rename operation is used to rename the output relation. It is denoted by rho (ρ). ■ Example:We can use the rename operator to rename STUDENT relation to STUDENT1. ■ ρ(STUDENT1, STUDENT)
  • 20. RDBMS:What isTable ? ■ In Relational database model, a table is a collection of data elements organised in terms of rows and columns.A table is also considered as a convenient representation of relations. But a table can have duplicate row of data while a true relation cannot have duplicate data.Table is the most simplest form of data storage. Below is an example of an Employee table. ID Name Age Salary 1 Adam 34 13000 2 Alex 28 15000 3 Stuart 20 18000 4 Ross 42 19020
  • 21. RDBMS:What is aTuple? ■ A single entry in a table is called a Tuple or Record or Row.A tuple in a table represents a set of related data. For example, the above Employee table has 4 tuples/records/rows. ■ Following is an example of single record or tuple. ■ 1 Adam 34 13000
  • 22. RDBMS:What is an Attribute? ■ A table consists of several records(row), each record can be broken down into several smaller parts of data known as Attributes. The above Employee table consist of four attributes, ID, Name, Age and Salary ■ Attribute Domain – When an attribute is defined in a relation(table), it is defined to hold only a certain type of values, which is known as Attribute Domain. – Hence, the attribute Name will hold the name of employee for every tuple. If we save employee's address there, it will be violation of the Relational database model. Name Adam Alex Stuart - 9/401, OC Street, Amsterdam Ross
  • 23. Cardinality (Degree of Relationship) ■ The degree of relationship can be defined as the number of occurrences in one entity that is associated with the number of occurrences in another entity. ■ There is the three degree of relationship: ■ One-to-one (1:1) ■ One-to-many (1:M) ■ Many-to-many (M:N)
  • 24. 1. One-to-one ■ In a one-to-one relationship, one occurrence of an entity relates to only one occurrence in another entity. ■ A one-to-one relationship rarely exists in practice. ■ For example: if an employee is allocated a company car then that car can only be driven by that employee. ■ Therefore, employee and company car have a one-to-one relationship.
  • 25. 2. One-to-many ■ In a one-to-many relationship, one occurrence in an entity relates to many occurrences in another entity. ■ For example:An employee works in one department, but a department has many employees. ■ Therefore, department and employee have a one-to-many relationship.
  • 26. 3. Many-to-many ■ In a many-to-many relationship, many occurrences in an entity relate to many occurrences in another entity. ■ Same as a one-to-one relationship, the many-to-many relationship rarely exists in practice. ■ For example: At the same time, an employee can work on several projects, and a project has a team of many employees. ■ Therefore, employee and project have a many-to-many relationship.
  • 27. Degree of Relationship The number of participating entities in a relationship defines the degree of the relationship. ■ Unary ■ Binary = degree 2 ■ Ternary = degree 3 ■ n-ary = degree
  • 28. Unary (degree 1) ■ A unary relationship exists when both the participating entity type are the same. When such a relationship is present we say that the degree of relationship is 1. ■ For example, Suppose in a classroom, we have many students who belong to a particular club-like dance club, basketball club etc. and some of them are club leads. So, a particular group of student is managed by their respective club lead. Here, the group is formed from students and also, the club leads are chosen from students. So, the ‘Student’ is the only entity participating here. We can represent this relationship using the E-R diagram as follows:
  • 29. Binary (degree 2) ■ A binary relationship exists when exactly two entity type participates.When such a relationship is present we say that the degree is 2.This is the most common degree of relationship. It is easy to deal with such relationship as these can be easily converted into relational tables. ■ For example,We have two entity type ‘Customer’ and ‘Account’ where each ‘Customer’ has an ‘Account’ which stores the account details of the ‘Customer’. Since we have two entity types participating we call it a binary relationship.Also, one ‘Customer’ can have many ‘Account’ but each ‘Account’ should belong to only one ‘Customer’.We can say that it is a one-to-many binary relationship.
  • 30. Ternary(degree 3) ■ A ternary relationship exists when exactly three entity type participates.When such a relationship is present we say that the degree is 3. As the number of entity increases in the relationship, it becomes complex to convert them into relational tables. ■ For example,We have three entity type ‘Employee’, ‘Department’ and ‘Location’.The relationship between these entities are defined as an employee works in a department, an employee works at a particular location. So, we can see we have three entities participating in a relationship so it is a ternary relationship.The degree of this relation is 3.
  • 31. N-ary (n degree) ■ An N-ary relationship exists when ‘n’ number of entities are participating. So, any number of entities can participate in a relationship.There is no limitation to the maximum number of entities that can participate. N
  • 32. Integrity Constraints ■ Integrity constraints are a set of rules. It is used to maintain the quality of information. ■ Integrity constraints ensure that the data insertion, updating, and other processes have to be performed in such a way that data integrity is not affected. ■ Thus, integrity constraint is used to guard against accidental damage to the database.
  • 33. Types of Integrity Constraint
  • 34. 1. Domain constraints ■ Domain constraints can be defined as the definition of a valid set of values for an attribute. ■ The data type of domain includes string, character, integer, time, date, currency, etc. The value of the attribute must be available in the corresponding domain.
  • 35. 2. Entity integrity constraints ■ The entity integrity constraint states that primary key value can't be null. ■ This is because the primary key value is used to identify individual rows in relation and if the primary key has a null value, then we can't identify those rows. ■ A table can contain a null value other than the primary key field.
  • 36. 3. Referential Integrity Constraints ■ A referential integrity constraint is specified between two tables. ■ In the Referential integrity constraints, if a foreign key inTable 1 refers to the Primary Key ofTable 2, then every value of the Foreign Key inTable 1 must be null or be available inTable 2.
  • 37. 4. Key constraints ■ Keys are the entity set that is used to identify an entity within its entity set uniquely. ■ An entity set can have multiple keys, but out of which one key will be the primary key. A primary key can contain a unique and null value in the relational table.
  • 38. 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. ■ For example: In Student table, ID is used as a key because it is unique for each student. In PERSON table, passport_number, license_number, SSN are keys since they are unique for each person.
  • 40. 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. ■ In the EMPLOYEE table, ID can be primary key since it is unique for each employee. In the EMPLOYEE table, we can even select License_Number and Passport_Number as primary key since they are also unique. ■ For each entity, selection of the primary key is based on requirement and developers.
  • 41. 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. ■ For example: In the EMPLOYEE table, id is best suited for the primary key. Rest of the attributes like SSN, Passport_Number, and License_Number, etc. are considered as a candidate key. ■
  • 42. 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. ■ For example: In the above EMPLOYEE table, for(EMPLOEE_ID, EMPLOYEE_NAME) the name of two employees can be the same, but their EMPLYEE_ID can't be the same. Hence, this combination can also be a key. ■ The super key would be EMPLOYEE-ID, (EMPLOYEE_ID, EMPLOYEE-NAME), etc.
  • 43. 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.