Anda di halaman 1dari 10

dbms E-R Diagram Mapping E-R diagram to relational model.

Indexing ( problem related to Indexing) Distributed Database advantage and disadvantages

Design the internal node structure for a B+ tree with following specifications. 5.1. Indexing is being done for *EMPLOYEE* relation where each record is of 128 bytes length. 5.2. The disk block size is 2048 bytes. * eid* and is of 10

5.3. The key attribute for the relation is bytes length. There are 4096 disk blocks.

Go through the last lecture -9 (Review Lecture) of DbSA, sir has covered this/similar example. ******************************************************************************** ***************************************** DBMS https://docs.google.com/#folders/0BxVD4t_ixhmhYmQ2MDZiYWItZjYwZi00MDE1LWI3M2ItYz VkYjhjZDViN2I5 SW for Embedded https://docs.google.com/#folders/0BxVD4t_ixhmhYWM2YzE4NDItNzMxZS00MTIwLWIwOGQtYj E1NDQ3NzYzOTk5 https://docs.google.com/#collections-shared-with-me CO QP https://docs.google.com/#folders/0BxVD4t_ixhmhYmMwNzg0NTgtNmI3ZC00ZGRiLTkyZWMtZm ZhZDdmNDBlZmZj Old ques papers http://discovery.bits-pilani.ac.in/dlpd/courses/opcontent.asp COSS To know what has to be done u can checkout slides of lec 2 and listen to lec8 vi deo 1st part..

Send me your resume at ashutosh.maheshwari@gmail.com.

Anybody else wishes to apply for testing/dev job in C/C++/Java/Optical domain, send me your resume. My organization is hiring.

Q 5. Identify the concurrency control problem in the following schedule and solve it using simple locking mechanism. Draw a state diagram of the existing schedule showing typical states that a transaction goes through during execution. Transaction A Time Transaction B T1 Read A(10) T2 If A > 10 then A = A+30 Read A(10) T3 A = A -3 T4 T5 Write A(40) T6 Commit Write A(7) T7 T8 Ans. a. There is a lost update issue of B in T5 being overwritten in T7 by A c. You can have the transaction B get an exclusive lock on data item A at T1. That way the attempt to read by A in T3 will be rejected and T3 will have to wait till T7 when B releases the lock. I have a slightly different approach, please validate my answer. T3(Read op - transaction A) happens before T5(Write op - Transac B), T5 (Write op - Transc B) happens before T7 (Write op - Transac A) A B There exist a loop so we need to have concurrency control here. To avoid loop we use locks as shown below Transaction A Time Transaction B T1 T2 Lock(A) Read A(10) If A > 10 then A = A+30

Read A(10) A = A -3 Unlock(A)

T3 T4

Lock(A) T5 Write A(40) Unlock(A) T6 Lock(A) Write A(7) Unlock(A) T8 for state diagram may be we need to draw states from T1 through T8, but not very sure about this. lect-15 In your solution, T1 T2 R(A) X(A) X(A) R(A) W(A) W(A) T2 gets the exclusive lock before T1 and it gets it after finishing the reading and just before doing the writing. Whereas T1 asks for it much earlier before even it completes reading. Shouldn't it be the foll or is it trivial? T1 T2 T7 Commit

S(A) R(A) Free S(A) X(A)==============> As per your desc, by getting a exclusive lock here, T1 will not even be able to get share lock. S(A) R(A) Free S(A) W(A) X(A) W(A)

In Pvs Year question papers, there are questions related with writing relational and SQL queries. Can some one please share the answers to such type of questions. Q.1. Look at the following Database schema. * * * *

*Student(sid, sname, sbranch) *Company(cid, cname, clocation) *Interview(sid, cid, interviewdate) *Placement(sid, cid, salary)

Now, write Relational Algebra query expressions to: (i) Get the student_id and the student name for those students who have not been placed in any company. (ii) Get the student_id and name for those students who have got placement in more than 3 companies. (iii) List the student_id with name for those students who have got placements in all the companies that have interviewed them. (iv) List the student_id, branch, company_id, company_name and its location for the students who got placements. [4 x 3 = 12]

Q.2.

Look at the following Database schema. * * *{ *brid * is FK

*BankBranch(brid, brlocation, brmanager ) *Customer(custid, custname, custaddress) *Account(accno, acctype, accbalance, brid) referring to *BankBranch *relation } *Cust_account(custid, accno) Now, write SQL query expressions to: *

(i) Get all the account numbers which are owned by more than one customer (i.e., joint accounts). (ii) Retrieve the account number and balance amount for those accounts which are not joint accounts. (iii) Get the branch number and location of those branches which do not have any accounts yet. (iv) List the all the account numbers and their balance amount, ordered in descending order on the balance amount (i.e., the account with highest balance should appear first ). Q.3. Look at the following Database schema. * //info about rivers passing

*River(**rivername**, length) *River_state(**rivername**, stname) through/touching states *

*Project(**projid,** projname, rivername, stname) projects on rivers* *State(**stname**, capital, area, population) Now, write Relational Algebra query expressions to:

// info about

(i) Get the list of rivers that pass through more than 3 states with population more than 2.0 crores.

(ii) Get the state name and its capital for those states that have no projects. (iii) it. Give the states that have all the rivers flowing through

Now, write Tuple Relational Calculus query expressions to: (iv) Get the projectID and name for those projects which are located in states with population more than 3.0 crores. [4 x 3 = 12] Q4: Consider the database schema and data retrieval requests given in Question-3 and write SQL queries for the same requirements.

1st NF : No multiple attributes should be there This means that in a table only one attribute should be there.. For example if there is a column as Phone number, then that column should be only used for entering one phone number. If you want to enter multiple you can have multiple rows.. 2nd NF : It says that there shouldn't be any non-prime attribute depends upon part of the the primary key.. Here its explained that suppose we have AB as primary key, so its not possible that D depends on B ( B is the part of the primary key) 3NF : This explains that if X depends upon A. Then either X should be a super key or A must be a prime attribute.... FOR BCNF : If X depends on A , then X must be a super key.

3NF : This explains that if X depends upon A. Then either X should be a super key or A must be a prime attribute.... FOR BCNF : If X depends on A , then X must be a super key.

Some additions This is transitive kind of relationship with A->B, B->C, But only A is a super key. 3NF: If B is super key or If C itselt is a prime attribute then its 3NF. eg: AC(PK)->B, B->C is 3NF BCNF: Here B has to be a super key also. AC(PK)->B, B->C is not BCNF since B is not a super key. Break it into two releations AC->B B->C Normalizing to BCNF may be very confusing and difficult though. Rectify me if mistaken.

Consider the universal relation R = {A, B, C, D, E, F, G, H, I} and the set of functional dependencies F = { {A, B} -> {C}, {A} -> {D, E}, {B} -> {F}, {F} ->{G, H}, {D} -> {I, J} }. What is the key for R? Decompose R into 2NF, then 3NF relations.

Key: AB (together they represent all the items in R) 2NF: R1 = A B C R2 = ADEIJ R3 = BFGH 3NF: R1 = ABC R2= AD R3 = DIJ R4 = BF R5= FGH

Give the highest normal form of the given relation R(A,B,C,D) with following functional dependencies as given : A B->CD, C-> B . Provide the next higher normalized schema for the given relation. This ans is not sure.

Q.1. Design the internal node structure for a B+ tree with following specifications. 5.1. Indexing is being done for *EMPLOYEE* relation where each record is of 128 bytes length. 5.2. The disk block size is 2048 bytes. * eid* and is of 10

5.3. The key attribute for the relation is bytes length. There are 4096 disk blocks. Can any one tell the solution for this???

Size of B+ tree node = size of disk block = 1024 bytes Each tree pointer points to disk block and takes 4 Bytes.(trick here is 2^4 = 1024 i.e. 4bytes are needed to represent a given node of address size 1024bytes) Each key (eid) takes 10 Bytes In a B+ tree node, No. of pointers = no. keys +1 Assume that no. keys = n; Then no. pointers= n+1 Then min. size for a node= {(no.Keys* size of each key)+ (no.pointers * size of each pointer)} <= 1024 (n*10)+(n+1)*4 <=1024 14n+4n+4 <= 1024 14n= 1020 and n=72 hence no. keys=72; and no. pointers=73

Q.1 What is the highest NF satisfied by the following relation ? R(A, B, C, D) FDs: { AB->C, AB-> D, B->D} Solution: The candidate key for R is AB. And there exists a partial dependency as B(part of the key) determines D. 2 NF v iolated, hence 1nf highest NF. For AB --> C its in BCNF

AB --> D its in BCNF B -->D is in 1NF It voilates 2NF because B is a part of key and B --> D which leads to partial dependency.

Q.2 Discuss with suitable examples the two special cases(anomalies) resolved by BCNF but not by 3NF. Give the highest normal form of the given relation R(A,B,C,D) with following functional dependencies as given : A B CD, C B . Provide the next higher normalized schema for the given relati on. How can a save point be used in deadlock resolution?

Q.3 Which of the following schedules is (conflict) serializable? For each serial izable schedule, determine the equivalent serial schedules. a. R1(X);R3(X);W(X);R2(X);W3(X); {lets assume W(x) as W1(X)} b. R1(X);R3(X);W3(X);W1(X);R2(X); c. R3(X);R2(X);W3(X);R1(X);W1(X); d. R3(X);R2(X);R1(X);W3(X);W1(X); Solution: a) since there is cycle ....sequence is not serializable. T1 T2 T3 R1(X) R3(X) W1(X) R2(X) W3(X) b) There is no cycle hence it is serializable.....sequence is ? can some one explain this pls T1 T2 T3 R1(X) R3(X) W3(X) W1(X) R2(X) c). There is no cycle hence it is serializable.....sequence is ? can some one explain this pls T1 T2 T3 R3(X) R2(X) W3(X) R1(X) W1(X) Talking abt B) We 1) 2) 3) can draw edge from ti to tj if foll Ti executes W(Q) before Tj executes Ti executes R(Q) before Tj executes Ti executes W(Q) before Tj executes conditions are satisfied: R(Q). W(Q). W(Q).

in case of b) T3 reads the data before T1 writes to it, so an edge can be drawn from T3 to T1. T2 reads data before T3 writes to it so an edge can be drawn from T3 to T2. But there isn't any edge from T1 to either T2 or T3. so, NO CYCLES ARE FORMED :)

Explaination step 1. T1 T2 T3 R1(X) R3(X)

W3(X) W1(X) R2(x) since R3(x) and R1(X) is non confilctiing we can sqwap their positions. so that it will become T1 T2 T3 R3(X) R1(X) W3(X) W1(X) R2(x) it is not serializable..... now there is a cycle between t1 and t3 hece

final answer (b) is not serializable right? There exists a cycle betwen t1 and t3 a) and b) have cycles c) doesn't have a cycle.

Serial schedule in c is simple - flip R2(x) and R3(x) - you have a serial schedu le. Although not mentioned in slides u can swap read steps on the same data item . Lets check the c part here c. R3(X);R2(X);W3(X);R1(X);W1(X); *1* From T3 to T1 ( W3(x) before W1(x) ) *2.* From T2 to T3 ( R2(x) before W3(X) ) Is that correct ?? Q.4 Consider the universal relation R = {A, B, C, D, E, F, G, H, I} and the set of functional dependencies F = { {A, B} -> {C}, {A} -> {D, E}, {B} -> {F}, {F} ->{G, H}, {D} -> {I, J} }. What is the key for R? Decompose R into 2NF, then 3NF relations. Solution: http://groups.google.com/group/BitsMSSS/browse_thread/thread/7897b81137103b36 http://groups.google.com/group/BitsMSSS/browse_thread/thread/bed1da1653509c08?pl i=1

http://www.google.com/url?sa=D&q=http://www.youtube.com/watch%3Fv%3Ds1DNVWKeQ_w &usg=AFQjCNFVL_FFZKQw1fu01hXNflXcvqhl6A http://www.youtube.com/watch?v=s1DNVWKeQ_w

Anda mungkin juga menyukai