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

PPTX
Database Design and Normalization Techniques
DOCX
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
PDF
The Relational Data Model and Relational Database Constraints
PPTX
Dbms relational data model and sql queries
PDF
Chapter 2 Relational Data Model-part1
PPT
Dbms ii mca-ch4-relational model-2013
PPT
3. Relational Models in DBMS
PPTX
Chapter 4
Database Design and Normalization Techniques
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints
Dbms relational data model and sql queries
Chapter 2 Relational Data Model-part1
Dbms ii mca-ch4-relational model-2013
3. Relational Models in DBMS
Chapter 4

What's hot (20)

PPTX
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
PPT
Intro to relational model
PDF
Sv data types and sv interface usage in uvm
PDF
Chapter 2 Relational Data Model-part 2
PPTX
Normalisation
PPTX
The relational data model part[1]
PPTX
Relational database intro for marketers
PPTX
Chapter 6 relational data model and relational
PPTX
SQL Queries Information
DOCX
Database Assignment
PPTX
Database : Relational Data Model
PDF
4 the relational data model and relational database constraints
PDF
Relational Model - An Introduction
PPT
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
PPTX
Fundamentals of database system - Relational data model and relational datab...
PPTX
Chapter 6 relational data model and relational
PPTX
Referential integrity
PPTX
Expression tree
PPTX
Dbms ER Model
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
Intro to relational model
Sv data types and sv interface usage in uvm
Chapter 2 Relational Data Model-part 2
Normalisation
The relational data model part[1]
Relational database intro for marketers
Chapter 6 relational data model and relational
SQL Queries Information
Database Assignment
Database : Relational Data Model
4 the relational data model and relational database constraints
Relational Model - An Introduction
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
Fundamentals of database system - Relational data model and relational datab...
Chapter 6 relational data model and relational
Referential integrity
Expression tree
Dbms ER Model
Ad

Similar to RDBMS (20)

PPTX
introduction to database system concepts 2
PPT
Unit04 dbms
PDF
4_RelationalDataModelAndRelationalMapping.pdf
PPT
4. SQL in DBMS
PPT
Unit 04 dbms
PPT
chapter4 contains details about sql queries.ppt
PPTX
relational model.pptx
PPT
Module 2 - part i
PPT
04 Introduction to SQ(Structural Query Language)L.ppt
PPT
relational algebra and it's implementation
PPTX
Module 2 2022 scheme BCS403 database management system
PPTX
DBMS Module-2 notes for engineering BE vtu
PPT
6. Integrity and Security in DBMS
PPT
UNIT 2 Structured query language commands
PDF
Relational Database and Relational Algebra
PDF
Relational Database Model Database Management system
PPTX
database chapter 6.pptx advanced database
PPTX
Chapter 6 relational data model and relational
introduction to database system concepts 2
Unit04 dbms
4_RelationalDataModelAndRelationalMapping.pdf
4. SQL in DBMS
Unit 04 dbms
chapter4 contains details about sql queries.ppt
relational model.pptx
Module 2 - part i
04 Introduction to SQ(Structural Query Language)L.ppt
relational algebra and it's implementation
Module 2 2022 scheme BCS403 database management system
DBMS Module-2 notes for engineering BE vtu
6. Integrity and Security in DBMS
UNIT 2 Structured query language commands
Relational Database and Relational Algebra
Relational Database Model Database Management system
database chapter 6.pptx advanced database
Chapter 6 relational data model and relational
Ad

More from NilaNila16 (14)

PPTX
Basic Block Scheduling
PPTX
Affine Array Indexes
PPTX
Software Engineering
PPTX
Web Programming
PPTX
MapReduce Paradigm
PPTX
Hadoop Distributed File System
PPTX
Data Mining
PPTX
Operating system
PPTX
Linear Block Codes
PPTX
Applications of graph theory
PPTX
Hasse Diagram
PPTX
Fuzzy set
PPTX
Recurrence Relation
PPTX
Input/Output Exploring java.io
Basic Block Scheduling
Affine Array Indexes
Software Engineering
Web Programming
MapReduce Paradigm
Hadoop Distributed File System
Data Mining
Operating system
Linear Block Codes
Applications of graph theory
Hasse Diagram
Fuzzy set
Recurrence Relation
Input/Output Exploring java.io

Recently uploaded (20)

PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
International_Financial_Reporting_Standa.pdf
PPTX
20th Century Theater, Methods, History.pptx
PDF
What if we spent less time fighting change, and more time building what’s rig...
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
TNA_Presentation-1-Final(SAVE)) (1).pptx
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PDF
HVAC Specification 2024 according to central public works department
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Unit 4 Computer Architecture Multicore Processor.pptx
International_Financial_Reporting_Standa.pdf
20th Century Theater, Methods, History.pptx
What if we spent less time fighting change, and more time building what’s rig...
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
History, Philosophy and sociology of education (1).pptx
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
LDMMIA Reiki Yoga Finals Review Spring Summer
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
TNA_Presentation-1-Final(SAVE)) (1).pptx
AI-driven educational solutions for real-life interventions in the Philippine...
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
HVAC Specification 2024 according to central public works department
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Virtual and Augmented Reality in Current Scenario
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Practical Manual AGRO-233 Principles and Practices of Natural Farming

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.