advanced database systems by- jesmin akhter assistant professor, iit, jahangirnagar university
TRANSCRIPT
![Page 1: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/1.jpg)
Advanced Database Systems
By-
Jesmin Akhter
Assistant Professor, IIT, Jahangirnagar University
![Page 2: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/2.jpg)
Lecture 06Overview of Relational DBMS
![Page 3: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/3.jpg)
Outline
Overview of Relational DBMS Relational Algebra
![Page 4: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/4.jpg)
Additional Operations
We define additional operations that do not add any power to the relational algebra, but that simplify common queries.
Set intersection
Natural join
Division
Assignment
Slide 4
![Page 5: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/5.jpg)
Set-Intersection Operation Notation: r s Defined as: r s ={ t | t r and t s } Assume:
r, s have the same arity
attributes of r and s are compatible
Note: r s = r - (r - s)
Slide 5
![Page 6: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/6.jpg)
Set-Intersection Operation - Example Relation r, s:
r s
A B
121
A B
23
r s
A B
2
Slide 6
![Page 7: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/7.jpg)
Notation: r s
Natural-Join Operation Let r and s be relations on schemas R and S respectively.
Then, r s is a relation on schema R S obtained as follows:
Consider each pair of tuples tr from r and ts from s.
If tr and ts have the same value on each of the attributes in R S, add a
tuple t to the result, where
t has the same value as tr on r
t has the same value as ts on s
Example:
R = (A, B, C, D)
S = (E, B, D)
Result schema = (A, B, C, D, E)
r s is defined as:
r.A, r.B, r.C, r.D, s.E (r.B = s.B r.D = s.D (r x s)) Slide 7
![Page 8: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/8.jpg)
Natural Join Operation – Example Relations r, s:
A B
12412
C D
aabab
B
13123
D
aaabb
E
r
A B
11112
C D
aaaab
E
s
r s
Slide 8
![Page 9: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/9.jpg)
Result of customer-name, branch-name(depositor account)
9
Result of customer-name, loan-number, amount (borrower loan)
![Page 10: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/10.jpg)
Division Operation
Suited to queries that include the phrase “for all”. Let r and s be relations on schemas R and S respectively
where
R = (A1, …, Am, B1, …, Bn)
S = (B1, …, Bn)
The result of r s is a relation on schema
R – S = (A1, …, Am)
r s = { t | t R-S(r) u s ( tu r ) }
r s
Slide 10
![Page 11: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/11.jpg)
Division Operation – Example
Relations r, s:
r s: A
B
1
2
A B
12311134612
r
s
11
![Page 12: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/12.jpg)
Another Division Example
A B
aaaaaaaa
C D
aabababb
E
11113111
Relations r, s:
r s:
D
ab
E
11
A B
aa
C
r
s
12
![Page 13: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/13.jpg)
Division Operation (Cont.)
r s = R-S (r) –R-S ( (R-S (r) x s) – R-S,S(r))
R-S,S(r) simply reorders attributes of r
R-S(R-S (r) x s) – R-S,S(r)) gives those tuples t in R-S (r) such that for some tuple u s, tu r.
Slide 13
![Page 14: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/14.jpg)
Assignment Operation The assignment operation () provides a convenient way to
express complex queries. Write query as a sequential program consisting of
a series of assignments followed by an expression whose value is displayed as a result of
the query. Assignment must always be made to a temporary relation variable.
Example: Write r s as
temp1 R-S (r)
temp2 R-S ((temp1 x s) – R-S,S (r))
result = temp1 – temp2
The result to the right of the is assigned to the relation variable on the
left of the .
May use variable in subsequent expressions.
Slide 14
![Page 15: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/15.jpg)
Example Queries
Find all customers who have an account from at least the “Downtown” and the Uptown” branches.
where CN denotes customer-name and BN denotes
branch-name.
Query 1
CN(BN=“Downtown”(depositor account))
CN(BN=“Uptown”(depositor account))
Slide 15
![Page 16: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/16.jpg)
Find all customers who have an account at all branches located
in Brooklyn city.
Example Queries
customer-name, branch-name (depositor account)
branch-name (branch-city = “Brooklyn” (branch))
Slide 16
depositor account branch
![Page 17: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/17.jpg)
Result of branch-name(branch-city =
“Brooklyn”(branch))
17
![Page 18: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/18.jpg)
Outer Join
An extension of the join operation that avoids loss of information. Computes the join and then adds tuples form one relation that
does not match tuples in the other relation to the result of the join.
Slide 18
![Page 19: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/19.jpg)
Outer Join – Example
Relation loan
Relation borrower
customer-name loan-number
JonesSmithHayes
L-170L-230L-155
300040001700
loan-number amount
L-170L-230L-260
branch-name
DowntownRedwoodPerryridge
Slide 19
![Page 20: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/20.jpg)
Outer Join – Example Inner Join
loan Borrower
loan-number amount
L-170L-230
30004000
customer-name
JonesSmith
branch-name
DowntownRedwood
JonesSmithnull
loan-number amount
L-170L-230L-260
300040001700
customer-namebranch-name
DowntownRedwoodPerryridge
Left Outer Join loan Borrower
Slide 20
![Page 21: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/21.jpg)
Outer Join – Example Right Outer Join loan borrower
loan borrower
Full Outer Join
loan-number amount
L-170L-230L-155
30004000null
customer-name
JonesSmithHayes
branch-name
DowntownRedwoodnull
loan-number amount
L-170L-230L-260L-155
300040001700null
customer-name
JonesSmithnullHayes
branch-name
DowntownRedwoodPerryridgenull
Slide 21
![Page 22: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/22.jpg)
Null Values
It is possible for tuples to have a null value, denoted by null, for some of their attributes
null signifies an unknown value or that a value does not exist. The result of any arithmetic expression involving null is null.
Slide 22
![Page 23: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/23.jpg)
Modification of the Database The content of the database may be modified using the following
operations: Deletion
Insertion
Updating
All these operations are expressed using the assignment operator.
Slide 23
![Page 24: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/24.jpg)
Deletion Examples
Delete all account records in the Perryridge branch.
Delete all loan records with amount in the range of 0 to 50
loan loan – amount 0and amount 50 (loan)
account account – branch-name = “Perryridge” (account)
Slide 24
![Page 25: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/25.jpg)
Insertion Examples Insert information in the database specifying that Smith has
$1200 in account A-973 at the Perryridge branch.
Provide as a gift for all loan customers in the Perryridge branch, a $200 savings account. Let the loan number serve as the account number for the new savings account.
account account {(“Perryridge”, A-973, 1200)}
depositor depositor {(“Smith”, A-973)}
r1 (branch-name = “Perryridge” (borrower loan))
account account branch-name, account-number,200 (r1)
depositor depositor customer-name, loan-number(r1)
Slide 25
![Page 26: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/26.jpg)
Update Examples Make interest payments by increasing all balances by 5 percent.
Pay all accounts with balances over $10,000 6 percent interest
and pay all others 5 percent
account AN, BN, BAL * 1.06 ( BAL 10000 (account))
AN, BN, BAL * 1.05 (BAL 10000 (account))
account AN, BN, BAL * 1.05 (account)
where AN, BN and BAL stand for account-number, branch-name and balance, respectively.
Slide 26
![Page 27: Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649f0b5503460f94c1ede6/html5/thumbnails/27.jpg)
Thank You