3.2k views

Consider a relation geq which represents "greater than or equal to", that is, $(x,y) \in$ geq only if $y \geq x$.

create table geq
(
ib	integer	not null,
ub	integer	not null,
primary key ib,
foreign key (ub) references geq on delete cascade
);

Which of the following is possible if tuple (x,y) is deleted?

1. A tuple (z,w) with z > y is deleted
2. A tuple (z,w) with z > x is deleted
3. A tuple (z,w) with w < x is deleted
4. The deletion of (x,y) is prohibited

edited | 3.2k views
0
M NOT GETTING THIS ?hOW TO APPROACH ?
0
A tuple (z,w) with x=w is deleted
+5
for example if you have geq table as:

A    B

1     2

2     3

3     4

4     4

if we delete last tuple(4,4) than you need to delete  all abve 3 tuples so this give relation as ,if you delete(x,y) than (z,w) with w<=x is deletd..
0
Think there is a tuple 1,5 instead of 1,2

And for satisfying foreign key constraint add 5,5 in table
0
than 1,5 would not be deleted if you delte 4,4 becz  that wont satisfy w<=x condn..
0

Sorry shubham, i didn't  gave correct example

A  B

0  2

1  3

3  7

2  4

4  5

5  9

9  11

7  7

11 11

Now delete 4,5 ====> your analyse will delete 1,3 also

What i am saying by my analogy

We want to delete

4  5 =====> you have to delete 2 4 ===> For deleting 2  4, You have to delete 0  2

0
yes but with respect to 4,5 i.e x,y u delte 0,2 i.e z,w here w<x naa..so its a condition that people with w<=x can be dleted not that everyone falling in this range would be deleted..
0
i am not getting, finally what you want to say...
0
bro qsn has asked if you delte 4,5

than 2,4 and 0,2 are deleted both are having w<=x with respect to 4,5 so what u would say as general condn if u delte some x,y than which tuple z,w would be delted along with this..are you getting..?
0
ok, now i understood, your previous comment

exact answer is not matching, but C is most relevant among them.
0
@shaikh yes..!
+10

https://www.geeksforgeeks.org/gate-gate-cs-2001-question-50/

Solution becomes easier by taking examples

+1

"foreign key (ub) references geq" Means referring to primary key of table geq(if foreign key references to same table then referenced key must be primary key of same table with same data type). In this case Parent table(Foreign key column) and child table (referenced column) both denoting same table.

Referenced column by Foreign key in same table or in child table must be a primary key.

NOTE-If more than 1 table involved in foreign key then you can replace the word primary key with candidate key above.

The table can be depicted as:

$$\begin{array}{|c|c|c|} \hline \textbf{ib(PK)} & \textbf {ub(FK)} \\\hline \text {z} & \text{w = u}\\\hline \text{u} & \text{v = x} \\\hline \text{x} & \text{y} \\\hline \end{array}$$

If $(x,y)$ is deleted then from the above table:

• $v\leq y$ $($as $v=x)$
• $u<v\leq y, u!=v$ $($as $v=x$ and ib is the Primary Key$)$
• $w<v\leq y$ $($as $w=u)$
• $z<w<v\leq y, z!=w$ $($as $w=u$ and ib is the Primary Key$)$

As, it can be seen that $w<v$ or $w<x$ $($as $v=x)$ so C is the answer.

by Boss (33.9k points)
edited
0
How C?
0
Updated.
+2
Hey Rajarshi,how are you assuming is w=u? and v=x? of couse if it is so, then definitely obvious. Also the question says x>w, it should have been x>=w. w != x, so how can we deduce?
0
After seeing this question i got know clue how to approach this one.Can u suggest how did u think of this way?

and please cite some source from where i can learn to solve this type of questions?
+2
@Bikram Sir @Arjun Sir, Little confusion please clarify 'y' is an element in ub which is a foreign key that means it should hold those elements which are present in lb but there is no 'y' in lb?
0
Thank you, very well explained. :)
0
If we have relation instance like below.

ib           ub
1              2
2              2
3              3

And we delete (3, 3) then what would be the result?

Update:

I wonder this is the case where option C does not hold. But there are cases in which option C is true too.

Now as we have asked 'which option is possible' the answer is C.
0
Let the tuples are

x y
l m
z w
Such that m=x and w=l then the relation among the values such that the tuples can insert in the relation so that it satisfies the given relation is. z <=w=l <=m=x <=y .so this relation only satisfied by option C.
0
what a nice way to approach ,,,thanks rajarishi sir
0

@ankyAS when you solve by taking an example in any example, form example such that it will be worst case. I mean here it is given that on delete cascade, form example when there will be many cascading delete due to deletion of one tuple. In second cascade delete you will get the answer. :)

0

w <= x (and also z<=x) would be the correct option.

Say suppose (2,3) is deleted then we additionally delete (2,2). That is the reason we need to have <= and not just <.

Ex:

 lb ub 0 0 0 1 0 2 0 3 1 1 1 2 1 3 2 2 2 3 3 3

If in this table (2,3) is deleted, then additionally we need to delete the below records:

 lb ub 0 0 0 1 0 2 1 1 1 2 2 2

But this is wrong, because we can't have duplicates in the primary key (ib) in the first place.

Hence Option C is correct.

0
Here two conditions are given and asked for inner relation

One is $(x,y)$, where $y>x$

another $(z,w)$, where $w>z$

then what relation in between possible for on delete cascade

i.e. $\left ( y,z \right )$ where $z>y$ and it is matching with option C)
0

@srestha

I realized my mistake.

We can't have duplicates in primary key. (Edited my comment as well)

0
Actually, it is a simple query, but asked in a twisted manner.

See, if we write three relation $\left ( x,y \right ),\left ( y,z \right ),\left ( z,w \right )$, then see there is a on delete cascade relationship in it. But in question they have only given $\left ( x,y \right ),\left ( z,w \right )$and asked to find inner one, that is $\left ( y,z \right )$

tuple (x,y) is to be deleted so let's take it into relation.

Now we have to observe the effect on tuple (z,w) so we will take it also in our table.

So till now, we are having two tuples, (x,y) and (z,w). Now let's consider each option:

a) z>y means (y,z) tuple is there. So deletion of (x,y) doesn't give any cascade relation between (x,y),(z,w) and (y,z)

b) z>x means (x,z) exists in relation. But since 'ib' is primary key, we can't repeat 'x' .

c) w<x means (w,x) exists. On deleting (x,y), (w,x) should be deleted and then (z,w) to maintain DELETE CASCADE.

Hence option C is correct choice

by Active (1.9k points)
edited by
0
if u have any material related to this topic then pls send me that link.
0
@1gate_cracker,
No as such link, just go through the concepts of "Referenced integrity constraints"...u will get everything required...
0
thank u
0
This is the best answer. Thank you!
0
nice it should be best answer
0
ans is C.

here they have mentioned "on delete cascade"

deleting (x,y), the relation having x as a greater value will also b deleted. in (z,w) w<x (x is greater) therefore it will also be deleted.
by Loyal (8.1k points)
0
Thanks for explanation
0
how w < x, if w =  x, then it will get deleted

Consider the below example

lb ub
5 8
3 5
8 8
2 3

Deleting first tuple will force us to delete 2 nd tuple

And deleting 2 nd tuple will force us to delete 4 th tuple.

Now because of deletion of first tuple (5,3), 4 th tuple (2,3) should be deleted ... Here z = 2 and x = 5 and z<x

So option C) is the answer ...

by Loyal (8k points)
edited
the relation schema is ( lb , ub ), where lb is the primary key, and ub is the foreign key which is referencing the primary key of its own relation.

Hence the table geq is both the master ( which has the referenced key ) as well as the child table (which has the referencing key).

The table has two constraint, one is that if there is a tuple ( x, y ), then y is greater than or equal to x, And the other is referential integrity constraint, which is on-cascade-delete on the foreign key.

On-cascade-delete says, that “When the referenced row is deleted from the other table (master table), then delete also from the child table”.

Suppose the instance in the given relation is the following:

x y
-----
5 6
4 5
3 4
6 6
Now if we delete tuple (5,6) then tuple ( 4,5 ) should also be deleted ( as 5 in the tuple (4, 5) was referencing to 5 in the tuple(5,6) which no longer exist, hence the referencing tuple should also be deleted), and as (4,5) got deleted hence tuple (3,4) should also be deleted for the same reason.

Therefore in total 3 rows have to be deleted if tuple ( 5,6 ) is deleted.

Now from the above instance we can say that if (x,y), i.e. ( 5,6 ) gets deleted then a tuple ( z, w) i.e, ( 3, 4) is also deleted. And we can see here that w < x. Hence option C.
by Active (1.6k points)