SlideShare a Scribd company logo
Relational Database Management System
Nadar Saraswathi College of Arts & Science
Submitted by
N. Nagapandiyammal
M. Sc (CS)
Content
• Basic Structure
• Set Operations
• Complex Queries
• Joined Relations
• Data-Definition Language(DDL)
Basic Structure
 SQL is based on set and relational operations with certain
modifications and enhancements
 A typical SQL query has the form
select A1,A2, ..., An
From r1,r2, ..., rm
Where P
 A is represent attributes
 r is represent relations
 P is a predicate
 This query is equivalent to the relational algebra expression:
ΠA1,A2, ..., An(P(r1 x r2 x...x rm))
 The result of an SQL query is a relation.
Set Operations
 The set operations union, intersect, and except operate on
relations and correspond to the relational algebra operations
[,, and −.
 Each of the above operations automatically eliminates
duplicates; to retain all duplicates use the corresponding
multiset versions union all, intersect all and except all.
Suppose a tuple occurs m times in r and n times in s, then, it
occurs:
m + n times in r union all s
min(m, n) times in r intersect all s
max(0,m−n) times in r except all s
 Find all customers who have a loan, an account, or both:
(Select customer-name from depositor)
union
(select customer-name from borrower)
 Find all customers who have both a loan and an account
(select customer- name from depositor)
intersect
(select customer-name from borrower)
 Find all customers who have an account but no loan.
(select customer-name from depositor)
except
(select customer-name from borrower)
Complex Queries
• Complex queries are often hard or impossible to write as a
single SQL block or a union / intersection / difference of
SQL blocks.
• Following are some very important Complex SQL Queries
Examples with answers. I have tried to explain each and
every query in detail so that everyone will get idea of how it
is executed step-by-step. Following are some Complex SQL
Queries Examples with answers in detail.
1.Query to find Second Highest Salary of Employee?
Answer:
Select distinct Salary from Employee e1
where 2=Select count(distinct Salary) from
Employee e2 where e1.salary<=e2.salary;
2.Query to find duplicate rows in table?
Answer:
Select * from Employee a where rowid <>( select
max(rowid) from Employee b where
a.Employee_num=b.Employee_num);
Joined Relations
o Join operations take two relations and return as a result another
relation.
o These additional operations are typically used as sub query
expressions in the from clause.
o Join condition – defines which tuple in the two relations match, and
what attributes are present in the result of the join.
o Join type – defines how tuple in each relation that do not match any
tuple in the other relation (based on the join condition) are treated.
Join Types
inner join
left outer join
right outer join
full outer join
Join Conditions
natural
on <predicate>
using (A1, A2, . . .,
An)
Joined Relations – Datasets for Examples
 Relation loan
 Relation borrower
branch-name loan-number amount
Downtown L-170 3000
Redwood L-230 4000
Perry ridge L-260 1700
customer-name loan-number
Jones L-170
Smith L-230
Hayes L-260
Joined Relations – Examples
 loan inner join borrower on
loan. loan-number =borrower. loan-number
 loan left outer join borrower on
loan. loan-number=borrower. loan-number
 loan natural inner join borrower
 loan natural right outer join borrower
 loan full outer join borrower using (loan-number)
Find all customers who have either an account or a loan (but
not both) at the bank.
select customer-name
from (depositor natural full outer join borrower)
where account-number is null or loan-number is null
Data Definition Language (DDL)
Allows the specification of not only a set of relations but
also information about each relation, including:
 The schema for each relation.
 The domain of values associated with each attribute.
 Integrity constraints.
 The set of indices to be maintained for each relation.
 Security and authorization information for each relation.
 The physical storage structure of each relation on disk.
Domain Types in SQL
 char(n). Fixed length character string, with user-
specified length n.
 varchar(n). Variable length character strings, with user-
specified maximum length n.
 int. Integer (a finite subset of the integers that is
machine-dependent).
 smallint. Small integer (a machine-dependent subset of
the integer domain type).
 numeric( p, d). Fixed point number, with user-specified
precision of p digits, with n digits to the right of decimal
point.
Domain Types in SQL (Cont.)
• real, double precision. Floating point and double-
precision floating point numbers, with machine-dependent
precision.
• float(n). Floating point number, with user-specified
precision of at least n digits.
• date. Dates, containing a (4 digit) year, month and date.
• time. Time of day, in hours, minutes and seconds.
– Null values are allowed in all the domain types. Declaring
an attribute to be not null prohibits null values for that
attribute.
– create domain construct in SQL-92 creates user-defined
domain types
create domain person-name char(20) not null
Create Table Construct
• An SQL relation is defined using the create table
command:
create table r (A1 D1, A2 D2, . . . , An Dn,
<integrity-constraint l >,
. . .,
<integrity-constraint>)
– r is the name of the relation
– each Ai is an attribute name in the schema of relation r
– Di is the data type of values in the domain of attribute Ai
Integrity Constraints In Create Table
 not null
 primary key (A1, . . ., An)
 check (P), where P is a predicate
Example: Declare branch-name as the primary key for
branch and ensure that the values of assets are non-negative.
create table branch
(branch-name char(15) not null,
branch-city char(30),
assets integer,
primary key (branch-name),
check (assets >= 0))
 primary key declaration on an attribute automatically
ensures not null in SQL-92
Drop and Alter Table Constructs
 The drop table command deletes all information about
the dropped relation from the database.
 The alter table command is used to add attributes to an
existing relation. All tuples in the relation are assigned null
as the value for the new attribute. The form of the alter
table command is
 alter table r add A D
 where A is the name of the attribute be added to relation r
and D is the domain of A.
 The alter table command can also be used to drop
attributes of a relation
 alter table r drop A
 where A is the name of an attribute of relation r.
The End

More Related Content

What's hot

FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
Vraj Patel
 
Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational model
ATS SBGI MIRAJ
 
Sv data types and sv interface usage in uvm
Sv data types and sv interface usage in uvmSv data types and sv interface usage in uvm
Sv data types and sv interface usage in uvm
HARINATH REDDY
 
Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2
Eddyzulham Mahluzydde
 
Normalisation
NormalisationNormalisation
Normalisation
Soumyajit Dutta
 
The relational data model part[1]
The relational data model part[1]The relational data model part[1]
The relational data model part[1]
Bashir Rezaie
 
Relational database intro for marketers
Relational database intro for marketersRelational database intro for marketers
Relational database intro for marketers
Steve Finlay
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relationalJafar Nesargi
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
Nishant Munjal
 
Database Assignment
Database AssignmentDatabase Assignment
Database Assignment
Jayed Imran
 
Database : Relational Data Model
Database : Relational Data ModelDatabase : Relational Data Model
Database : Relational Data Model
Smriti Jain
 
4 the relational data model and relational database constraints
4 the relational data model and relational database constraints4 the relational data model and relational database constraints
4 the relational data model and relational database constraintsKumar
 
Relational Model - An Introduction
Relational Model - An IntroductionRelational Model - An Introduction
Relational Model - An Introduction
Rajeev Srivastava
 
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
Shashi Patel
 
Fundamentals of database system - Relational data model and relational datab...
Fundamentals of database system  - Relational data model and relational datab...Fundamentals of database system  - Relational data model and relational datab...
Fundamentals of database system - Relational data model and relational datab...
Mustafa Kamel Mohammadi
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relationalJafar Nesargi
 
Referential integrity
Referential integrityReferential integrity
Referential integrity
Jubin Raju
 
Expression tree
Expression treeExpression tree
Expression tree
NagajothiN1
 
Dbms ER Model
Dbms ER ModelDbms ER Model
Dbms ER Model
Sreedhar Chowdam
 

What's hot (20)

FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
 
Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational model
 
Sv data types and sv interface usage in uvm
Sv data types and sv interface usage in uvmSv data types and sv interface usage in uvm
Sv data types and sv interface usage in uvm
 
Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2
 
Normalisation
NormalisationNormalisation
Normalisation
 
The relational data model part[1]
The relational data model part[1]The relational data model part[1]
The relational data model part[1]
 
Relational database intro for marketers
Relational database intro for marketersRelational database intro for marketers
Relational database intro for marketers
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
 
PPT
PPTPPT
PPT
 
Database Assignment
Database AssignmentDatabase Assignment
Database Assignment
 
Database : Relational Data Model
Database : Relational Data ModelDatabase : Relational Data Model
Database : Relational Data Model
 
4 the relational data model and relational database constraints
4 the relational data model and relational database constraints4 the relational data model and relational database constraints
4 the relational data model and relational database constraints
 
Relational Model - An Introduction
Relational Model - An IntroductionRelational Model - An Introduction
Relational Model - An Introduction
 
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
 
Fundamentals of database system - Relational data model and relational datab...
Fundamentals of database system  - Relational data model and relational datab...Fundamentals of database system  - Relational data model and relational datab...
Fundamentals of database system - Relational data model and relational datab...
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
 
Referential integrity
Referential integrityReferential integrity
Referential integrity
 
Expression tree
Expression treeExpression tree
Expression tree
 
Dbms ER Model
Dbms ER ModelDbms ER Model
Dbms ER Model
 

Similar to RDBMS

4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf
LPhct2
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMSkoolkampus
 
relational model.pptx
relational model.pptxrelational model.pptx
relational model.pptx
ThangamaniR3
 
Module 2 - part i
Module   2 - part iModule   2 - part i
Module 2 - part i
ParthNavale
 
relational algebra and it's implementation
relational algebra and it's implementationrelational algebra and it's implementation
relational algebra and it's implementation
dbmscse61
 
3.ppt
3.ppt3.ppt
6. Integrity and Security in DBMS
6. Integrity and Security in DBMS6. Integrity and Security in DBMS
6. Integrity and Security in DBMSkoolkampus
 
UNIT 2 Structured query language commands
UNIT 2 Structured query language commandsUNIT 2 Structured query language commands
UNIT 2 Structured query language commands
Bhakti Pawar
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational Algebra
Pyingkodi Maran
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relationalJafar Nesargi
 
Ch2
Ch2Ch2
DBMS Unit-2.pdf
DBMS Unit-2.pdfDBMS Unit-2.pdf
DBMS Unit-2.pdf
vaishnavi339314
 
6 integrity and security
6 integrity and security6 integrity and security
6 integrity and securityDilip G R
 
Ch4
Ch4Ch4
Relational model
Relational modelRelational model
Relational model
Dabbal Singh Mahara
 
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
Roshni814224
 
SQL PPT.ppt
SQL PPT.pptSQL PPT.ppt
SQL PPT.ppt
hemamalinikrishnan2
 

Similar to RDBMS (20)

Unit04 dbms
Unit04 dbmsUnit04 dbms
Unit04 dbms
 
4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMS
 
Unit 04 dbms
Unit 04 dbmsUnit 04 dbms
Unit 04 dbms
 
relational model.pptx
relational model.pptxrelational model.pptx
relational model.pptx
 
Module 2 - part i
Module   2 - part iModule   2 - part i
Module 2 - part i
 
relational algebra and it's implementation
relational algebra and it's implementationrelational algebra and it's implementation
relational algebra and it's implementation
 
3.ppt
3.ppt3.ppt
3.ppt
 
6. Integrity and Security in DBMS
6. Integrity and Security in DBMS6. Integrity and Security in DBMS
6. Integrity and Security in DBMS
 
UNIT 2 Structured query language commands
UNIT 2 Structured query language commandsUNIT 2 Structured query language commands
UNIT 2 Structured query language commands
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational Algebra
 
ch3
ch3ch3
ch3
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
 
Ch2
Ch2Ch2
Ch2
 
DBMS Unit-2.pdf
DBMS Unit-2.pdfDBMS Unit-2.pdf
DBMS Unit-2.pdf
 
6 integrity and security
6 integrity and security6 integrity and security
6 integrity and security
 
Ch4
Ch4Ch4
Ch4
 
Relational model
Relational modelRelational model
Relational model
 
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
 
SQL PPT.ppt
SQL PPT.pptSQL PPT.ppt
SQL PPT.ppt
 

More from NilaNila16

Basic Block Scheduling
Basic Block SchedulingBasic Block Scheduling
Basic Block Scheduling
NilaNila16
 
Affine Array Indexes
Affine Array IndexesAffine Array Indexes
Affine Array Indexes
NilaNila16
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
NilaNila16
 
Web Programming
Web ProgrammingWeb Programming
Web Programming
NilaNila16
 
MapReduce Paradigm
MapReduce ParadigmMapReduce Paradigm
MapReduce Paradigm
NilaNila16
 
Hadoop Distributed File System
Hadoop Distributed File SystemHadoop Distributed File System
Hadoop Distributed File System
NilaNila16
 
Data Mining
Data MiningData Mining
Data Mining
NilaNila16
 
Operating system
Operating systemOperating system
Operating system
NilaNila16
 
Linear Block Codes
Linear Block CodesLinear Block Codes
Linear Block Codes
NilaNila16
 
Applications of graph theory
                      Applications of graph theory                      Applications of graph theory
Applications of graph theory
NilaNila16
 
Hasse Diagram
Hasse DiagramHasse Diagram
Hasse Diagram
NilaNila16
 
Fuzzy set
Fuzzy set Fuzzy set
Fuzzy set
NilaNila16
 
Recurrence Relation
Recurrence RelationRecurrence Relation
Recurrence Relation
NilaNila16
 
Input/Output Exploring java.io
Input/Output Exploring java.ioInput/Output Exploring java.io
Input/Output Exploring java.io
NilaNila16
 

More from NilaNila16 (14)

Basic Block Scheduling
Basic Block SchedulingBasic Block Scheduling
Basic Block Scheduling
 
Affine Array Indexes
Affine Array IndexesAffine Array Indexes
Affine Array Indexes
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 
Web Programming
Web ProgrammingWeb Programming
Web Programming
 
MapReduce Paradigm
MapReduce ParadigmMapReduce Paradigm
MapReduce Paradigm
 
Hadoop Distributed File System
Hadoop Distributed File SystemHadoop Distributed File System
Hadoop Distributed File System
 
Data Mining
Data MiningData Mining
Data Mining
 
Operating system
Operating systemOperating system
Operating system
 
Linear Block Codes
Linear Block CodesLinear Block Codes
Linear Block Codes
 
Applications of graph theory
                      Applications of graph theory                      Applications of graph theory
Applications of graph theory
 
Hasse Diagram
Hasse DiagramHasse Diagram
Hasse Diagram
 
Fuzzy set
Fuzzy set Fuzzy set
Fuzzy set
 
Recurrence Relation
Recurrence RelationRecurrence Relation
Recurrence Relation
 
Input/Output Exploring java.io
Input/Output Exploring java.ioInput/Output Exploring java.io
Input/Output Exploring java.io
 

Recently uploaded

Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 

Recently uploaded (20)

Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 

RDBMS

  • 1. Relational Database Management System Nadar Saraswathi College of Arts & Science Submitted by N. Nagapandiyammal M. Sc (CS)
  • 2. Content • Basic Structure • Set Operations • Complex Queries • Joined Relations • Data-Definition Language(DDL)
  • 3. Basic Structure  SQL is based on set and relational operations with certain modifications and enhancements  A typical SQL query has the form select A1,A2, ..., An From r1,r2, ..., rm Where P  A is represent attributes  r is represent relations  P is a predicate  This query is equivalent to the relational algebra expression: ΠA1,A2, ..., An(P(r1 x r2 x...x rm))  The result of an SQL query is a relation.
  • 4. Set Operations  The set operations union, intersect, and except operate on relations and correspond to the relational algebra operations [,, and −.  Each of the above operations automatically eliminates duplicates; to retain all duplicates use the corresponding multiset versions union all, intersect all and except all. Suppose a tuple occurs m times in r and n times in s, then, it occurs: m + n times in r union all s min(m, n) times in r intersect all s max(0,m−n) times in r except all s
  • 5.  Find all customers who have a loan, an account, or both: (Select customer-name from depositor) union (select customer-name from borrower)  Find all customers who have both a loan and an account (select customer- name from depositor) intersect (select customer-name from borrower)  Find all customers who have an account but no loan. (select customer-name from depositor) except (select customer-name from borrower)
  • 6. Complex Queries • Complex queries are often hard or impossible to write as a single SQL block or a union / intersection / difference of SQL blocks. • Following are some very important Complex SQL Queries Examples with answers. I have tried to explain each and every query in detail so that everyone will get idea of how it is executed step-by-step. Following are some Complex SQL Queries Examples with answers in detail.
  • 7. 1.Query to find Second Highest Salary of Employee? Answer: Select distinct Salary from Employee e1 where 2=Select count(distinct Salary) from Employee e2 where e1.salary<=e2.salary; 2.Query to find duplicate rows in table? Answer: Select * from Employee a where rowid <>( select max(rowid) from Employee b where a.Employee_num=b.Employee_num);
  • 8. Joined Relations o Join operations take two relations and return as a result another relation. o These additional operations are typically used as sub query expressions in the from clause. o Join condition – defines which tuple in the two relations match, and what attributes are present in the result of the join. o Join type – defines how tuple in each relation that do not match any tuple in the other relation (based on the join condition) are treated. Join Types inner join left outer join right outer join full outer join Join Conditions natural on <predicate> using (A1, A2, . . ., An)
  • 9. Joined Relations – Datasets for Examples  Relation loan  Relation borrower branch-name loan-number amount Downtown L-170 3000 Redwood L-230 4000 Perry ridge L-260 1700 customer-name loan-number Jones L-170 Smith L-230 Hayes L-260
  • 10. Joined Relations – Examples  loan inner join borrower on loan. loan-number =borrower. loan-number  loan left outer join borrower on loan. loan-number=borrower. loan-number  loan natural inner join borrower  loan natural right outer join borrower  loan full outer join borrower using (loan-number) Find all customers who have either an account or a loan (but not both) at the bank. select customer-name from (depositor natural full outer join borrower) where account-number is null or loan-number is null
  • 11. Data Definition Language (DDL) Allows the specification of not only a set of relations but also information about each relation, including:  The schema for each relation.  The domain of values associated with each attribute.  Integrity constraints.  The set of indices to be maintained for each relation.  Security and authorization information for each relation.  The physical storage structure of each relation on disk.
  • 12. Domain Types in SQL  char(n). Fixed length character string, with user- specified length n.  varchar(n). Variable length character strings, with user- specified maximum length n.  int. Integer (a finite subset of the integers that is machine-dependent).  smallint. Small integer (a machine-dependent subset of the integer domain type).  numeric( p, d). Fixed point number, with user-specified precision of p digits, with n digits to the right of decimal point.
  • 13. Domain Types in SQL (Cont.) • real, double precision. Floating point and double- precision floating point numbers, with machine-dependent precision. • float(n). Floating point number, with user-specified precision of at least n digits. • date. Dates, containing a (4 digit) year, month and date. • time. Time of day, in hours, minutes and seconds. – Null values are allowed in all the domain types. Declaring an attribute to be not null prohibits null values for that attribute. – create domain construct in SQL-92 creates user-defined domain types create domain person-name char(20) not null
  • 14. Create Table Construct • An SQL relation is defined using the create table command: create table r (A1 D1, A2 D2, . . . , An Dn, <integrity-constraint l >, . . ., <integrity-constraint>) – r is the name of the relation – each Ai is an attribute name in the schema of relation r – Di is the data type of values in the domain of attribute Ai
  • 15. Integrity Constraints In Create Table  not null  primary key (A1, . . ., An)  check (P), where P is a predicate Example: Declare branch-name as the primary key for branch and ensure that the values of assets are non-negative. create table branch (branch-name char(15) not null, branch-city char(30), assets integer, primary key (branch-name), check (assets >= 0))  primary key declaration on an attribute automatically ensures not null in SQL-92
  • 16. Drop and Alter Table Constructs  The drop table command deletes all information about the dropped relation from the database.  The alter table command is used to add attributes to an existing relation. All tuples in the relation are assigned null as the value for the new attribute. The form of the alter table command is  alter table r add A D  where A is the name of the attribute be added to relation r and D is the domain of A.  The alter table command can also be used to drop attributes of a relation  alter table r drop A  where A is the name of an attribute of relation r.