amit ranjan final assm

Embed Size (px)

Citation preview

  • 8/7/2019 amit ranjan final assm

    1/6

    LOVELY PROFESSIONAL UNIVERSITY

    MODEL HOME WORK: 3

    School: LSTCADepar

    tment:CSE/IT

    Name of the faculty member: Geetika Mam

    Course No: CSE301

    Course Title: Database Management System

    Name : Amit Ranjan

    Section: E1802A22

    Date of Submission: March 31,2011

  • 8/7/2019 amit ranjan final assm

    2/6

    Que 1: Can we achieve 2NF without 1NF. Also differentiate 1NF and 2NF with an example?

    Ans1-: No we Cant achieve 2NF without the 1NF. For 2NF we must have all the attributes in firstnormal form and non key attributes are fully dependent on primary key attributes.

    1NF -: For a relation to be in 1NF we have the following conditions-:

    1) All the primary key attributes are defined

    2) Each row and column contain only one and one value ,not a set of values.

    3) All the attributes subject and are dependent on primary key

    For example we have a student table with attributes (rollno, name ,record(Subject,marks)). Thedata in the student table is not in normalized form because the attribute record contain multiplevalues. We can can covert it into normalized form i.e in 1NF form. By reducing non atomic valuesof subject and marks. We can reduce the it into 1NF by making rec_subjects and rec_marks asseprate attributes in a table . Then it will not contain any non atomic values and it is said to be innormalized form i.e 1NF. The combination of (roll no, rec_subjects) forming composite key.

    2NF-: For a relation to be in second normal form we have the following conditions-

    1) All the attributes must be in 1NF.

    2) All the non attributes should be fully dependent upon primary key.

    For example taking a relation named order-

    Order_no B_name Quantity B_price

    4200 Learn c 15 Rs.173

    4200 Database 20 Rs.123

    4100 IT 30 Rs.200

    4500 Learn c 50 Rs.173

    4400 Database 15 Rs. 123

    Here in this example (order_no,b_name ) act as the composite key i.e the primary key. So theattribute quantity is determined by the combination of these two attributes . B_price can bedetrmined with the only attribute B_name. So in the 2NF we can divide the following table intotwo tables showing functional dependency.

    Q u e s t i o n 2 : How is the concept of functional dependency associated with the processof normalization?

  • 8/7/2019 amit ranjan final assm

    3/6

    Ans2-: Any attribute in the relation is functionally dependent upon other if each value of one attributeis ass oci ate d w ith onl y on e va lue of oth er a t t r ib ute in ar e l a t i on .

    Following are the reasons-:

    1) For the 2NF all the non key attributes should be fully functionally dependent onprimary key of the relation.

    The example given in the above question explains the concept of functional dependency in the2NF. Inthis way f unctional dependenc y is fully associated with the process of no rmalizat ion i. e it he lps inderiving first three normal forms of normalization.

    Question 3: A relation R (A, B, C, D, E, F) have the following set of dependency:A->CD; B->C; F->DE ;F->AIs the decomposition of R in R1 (A, B, C,), R2 (A, F, D) and R3 (E, F)dependency reversing?

    Ans3-: In the relat ion R , A determines the combinat ion of Attr ibutes of CD , Bdetermines C ,Fdetermines DE and F determines A also. No the the decomposition of R intoR1,R2,R3 will not results in dependency reversing. It wi ll result s in to the 2ndnormalization form and 3 rd normalization forms of the relation i.e it will provide 2NF and 3NFforms.

    Question 4: Draw the state diagram showing various states of a transaction. Also give theworkingof this diagram.

    Ans4-: Following are the five states of transactions-:1) Active-:It is the state when the first operation of the transaction starts execu ting .This stateremains active until till all the operation ends.2) Partially commited -: T h i s i s t he s t a t e co mes wh en a l l t he op e ra t i o n a r ec o m p l e t e d a n d transaction moved to the commit state.3) Failed-: This is the state when the transaction stops because of some errors. If it fails then itgetsrollback and enters the other state.4) Aborted-: this is the state occurs When the transaction is rolled back and the databaserestoresback to original postion.5) Commited-: This is the state occurs when all the ope ration are performed and da tacomple tedsaved to database.

  • 8/7/2019 amit ranjan final assm

    4/6

    Question 5: Make a comparison between conflict and view serializability with an example.

    Ans5-: Serializibility is the concept which helps in understanding the non serial schedule which iscausing problems and which has same results as that of the transactions which are part of theschedule.

    Conflict Serializibilty-: A schedule is said to be conflict serializible if it is conflict equivalent toa serial schedule consider the following example in the schedule S1 the write(a) operation of T1conflicts with the read(a) operation of T2 but the read operation of T1 doesnt conflict with theWrite(a) operation of T2 because former both the operation with the same data A and one of themis write operation and in later case the two operations operating on different data items. So if weswap the order of non conflicting operations i.e read(b) of transaction T1 with write(a) of transaction T2 , we get a new schedule S2. S1 and S3 are conflict equivalent as schedule S1 canbe transferred into Schedule S3 By series of swaps to schedule S1.

    S1 S2 S3

    T1 T2

    Read(a)

    Write(a)

    Read(a)

    Write(a)

    T1 T2

    Read(a)

    Write(a)

    Read(a)Read(b)

    T1 T2

    Read(a)

    Write(a)

    Read(b)

    Write(b)

    Partialycommited

    commite

    d

    abortedfail

    ed

    Active

  • 8/7/2019 amit ranjan final assm

    5/6

    Read(b)

    Write(b)

    Read(b)

    Write(b)

    Write(a)

    Write(b)

    Read(b)

    Write(b)

    Read(a)

    Write(a)

    Read(b)

    Write(b)

    View Serializibility-: A schedule is said to be view serializible if it is view equivalent to serialschedule. Consider the following example-:

    S1 S2 S3

    T1 T2

    Read(a)

    A=A-100

    Write(a)

    Read(b)B=B+100

    Write(b)

    Read(a)

    T=A*02

    A=A-T

    Write(a)Read(b)

    T1 T2

    Read(a)

    T=A*0.2

    A=A-T

    Write(a)Read(b)

    B=B+T

    Write(b)

    Read(a)

    A=A-100

    Write(a)Read(b)

    B=B+100

    Write(b)

    T1 T2

    Read(a)

    A=A-100

    Write(a)

    Read(a)T=A*0.2

    A=A-T

    Write(a)

    Read(b)

    B=B+100Write(b)

    Read(b)

    B=B+T

    Write(B)

  • 8/7/2019 amit ranjan final assm

    6/6

    Schedule S1 and S3 are view Equivalent because the values of data item A and B read bytransaction T2 was produced by T1 in both the schedules. This shows the concept of viewserializibility.

    Question 6: Are the ACID properties of a transaction essential to ensure the

    integrity of data?Give an example of each property.

    Ans6-:Yes , the ACID properties of transactions are essential to ensure the integrity of data.Following are the properties-1)Atomicity-: It means that the whether all the changes are made to transaction and no change ismade. For example we have two accounts A and B we want to transfer money fromacco un t A to B.This means money is to be subtracted from account A and added to account B.A c c o rd in g t o t h i s property both these operations made simultaneously or none is made.

    2)Isolation-: This means th at whe n the two users are usin g same database the c hanges

    will bemade both of them concurrently i.e the data used during the execution of one transactioncannot be usedby the other transaction until the first one is completed.

    =========================