Sie sind auf Seite 1von 9

Green University of Bangladesh

Department of Computer Science and Engineering

Course Code: CSE 209


Course Title: Database System

Assignment Title:

Assignment On Final Examination

Student ID: 182002032


Student Name: Nahim Ahmed Rimon
Semester: Spring’20
Date of Submission: 07-06-2020

Submitted to:
MD ANSARUL ISLAM
Lecturer
Dept. of Computer Science and Engineering
Green University of Bangladesh
(1)To maintain the consistency of database during
transactions which properties are used? Briefly explain
each property.

Ans: A transaction is a collection of instructions. To maintain the


consistency of a database, all transactions must obey ACID properties.These
are:
1. Atomicity : A transaction is an atomic unit; hence, all the
instructions within a transaction will successfully execute, or none of
them will execute. The following transaction transfers 20 dollars from
Tisha’s bank account to Rahim’s bank account. If any of the
instructions fail, the entire transaction should abort and rollback.
Example:
T1
Read(A_bal)
A_bal -=20
Write(A_bal)
Read(B_bal)
B_bal +=20
Write(B_bal)

2. Consistency : A database is initially in a consistent state, and it


should remain consistent after every transaction. Suppose that the
transaction in the previous example fails after Write(A_b) and the
transaction is not rolled back then the database will be inconsistent as
the sum of Tisha and Rahim’s money, after the transaction, will not be
equal to the amount of money they had before the transaction.

3. Isolation : If the multiple transactions are running concurrently,


they should not be affected by each other the result should be the same
as the result obtained if the transactions were running sequentially.
Suppose B_bal is initially 100. If a context switch occurs after B_bal
*= 20, T2 will read the incorrect value of 100 as the updated value will
not have been written back to the database. This violates the isolation
property as the result is different from the answer that would have
been obtained if T1 had finished before T2.

Example:

T1 T2
Read(B_bal) Read(B_bal)
B_bal*=0.2 B_bal +=20
Write(B_bal) Write(B_bal)

4. Durability : Changes that have been committed to the database


should remain even in the case of software and hardware failure. For
instance, if Rahim’s account contains $120, this information should
not disappear upon hardware or software failure.

(2)Define conflict serializability. How to check if two


schedule S and S’ are conflict serializable or not- explain
with example.

Ans:
Conflict Serialzability : If a given non-serial schedule can be converted
into a serial schedule by swapping its non-conflicting operations, then it is
called as a conflict serializable schedule.

To check if two schedule S and S’ are conflict serializable or not is given


below:
We could tell it’s a conflict serializability when these conditions are
satisfied.These are

1. Both belong to separate transactions.


2. They have the same data item.
3. They contain at least one write operation.
Example of a conflict serializability :

T1 T2 T1 T2

Read(X) Write(X)
Swap
Read(Y) Write(Y)

Write(X) Read(X)

Write(Y) Read(Y)

Schedule S Schedule S’

This is a conflict serializable schedule.


Example of a non-conflict serializability :

T1 T2 T1 T2

Read(A) Read(A)

Read(B) Swap Read(B)

Read(A) Read(A)

Read(B) Read(B)

Schedule S Schedule S’

This is a non-conflict serializable schedule.


(3)Facebook database contains millions of records. There
are many people whose name is Mehedi Hasan in
Facebook.Now write a SQL query to find those records
whose first name starts with mehedi.Is there any problem
with the SQL query you have written.Facebook may take
long time to respond. What can be the efficient way-
explain with necessary SQL statements.

Ans: In facebook database, when we write a query in a simple way we all


know it does not define all the charecterstics of its form.So,when we throw
the SQL query at the database which contains millions of records it searched
linearly which take longer time to find a single data.
To avoid this kind of problem we used a fuction called hashing.Hashing finds
the data we need exactly.So we can use indexing to find this kind of data.But
indexing not save our time to find a single data and we all have to find our
data faster and exact.That’s why hashing is the perfect function to find a
reliable data.
Hashing
Hasihing can be an efficient way to locate the data.A hash function takes a
group of characters and maps it to a value of a certain length .The hash value
is representative of the original string of characters, but is normally smaller
than the original.
Hashing is done for indexing and locating items in databases because it is
easier to find the shorter hash value than the longer string. Hashing is also
used in encryption.
This term is also known as a hashing algorithm or message digest function.
For basic query we used the function that given below
SQL Select * from Facebook where First_Name=’mehedi’;
Its linearly find the data and takes longer time to find the data from this
kind of huge database.
Example of hash function to find a particular data:

Joy
101

Mehedi
102
HASHING
Rifath
103

Nila
104

Hashing Funtion with data blocks

(4)What is Functional Dependancy?


Stu_Id Std_Name Course_Id Course_Name Grade
Is there any partial functional dependency in the above
table- justify your answer.
Ans:
Fuctional Dependancy: Functional dependency is a relationship that
exists when one attribute uniquely determines another attribute.Functional
dependency in a database serves as a constraint between two sets of
attributes. Defining functional dependency is an important part of relational
database design and contributes to aspect normalization.

In the above table there is a partial fuctional dependency existed. As we see


table has five attributes Std_Id,Std_Name,Course_Id,Course_Name and
grade.Here Std_Id is the primary key but the attribute Course_Name is fully
denpendent on Course_Id.That’s why we can say that a partial dependency
existed in the above table.
Let me explain it with a suitable example:
Std_Id Std_Name Course_ Id Course_Name Grade

152 Nasir 101 Database 3.12

154 Meer 102 Statistics 3.00

Here a user does not find any match in his search for Course_name without
the Course_Id.For the partial fuctional dependency the user may find this
table given below.
Std_Id Std_Name Course_ Id

152 Nasir 101

154 Meer 102

For,Course_Name user can just only apply the query for the Course_Id in
spite of Stud_Id and it will show the Course_Name in the table.
For the Grade attribute we both need the Std_Id and Course_Id.
Std_IdStd_Name,Course_Id.
Course_IdCourse_Name(Partial Fuctional Dependency).
Std_Id,Course_IdGrade.
Course_Id Course_Name Std_Id Course_Id Grade

101 Database 152 101 3.12

102 Statistics 154 102 3.00


(5)See the below transaction.
T1 T2
R(A)
W(A)
R(A)
R(B)
R(B)
W(B)

Is this schedule conflict serializable- explain on your answer.


Ans:
Conflict Serialzability : If a given non-serial schedule can be converted
into a serial schedule by swapping its non-conflicting operations, then it is
called as a conflict serializable schedule.

The way conflict can recognize in a schedule:


1. Both belong to separate transactions.
2. They have the same data item.
3. They contain at least one write operation.

To do so first we swap between R(B) of T1 and R(B) of T2 . After the swapping


the transaction looks different.Beacause of the swapping the R(B) of T1 takes
the place of R(B) of T2 and the R(B) of T2 takes the place of R(B)of T1.They
are not conflicting.

T1 T2
R(A)
W(A)
R(A)
R(B)
R(B)
W(B)
Now after the first swap we can swap again for the R(B) of T1 and R(A) of
T2.After the swap R(B) of T1 takes place of R(A) of T2 and R(A) of T2 takes
the place of R(B) of T1.They are not conflicting.

T1 T2
R(A)
W(A)
R(B)
R(A)
R(B)
W(B)

After that we are going to swap W(B) of T1 and R(B) of T2 and now the
transaction can not be done because swapping for W(B) of T1 and R(B) of T2
are conflicting.
So by doing the swapping between 2 non-conflict operation and 1 conflicting
operation we can say that the avobe transaction cannot be serialized .So it is
not conflict serializable schedule.

The End

Das könnte Ihnen auch gefallen