联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Database作业Database作业

日期:2019-11-30 06:53

COMP518 Assignment 3 (of 3)

The submission of your solutions should be in PDF or DOC format. The MySQL commands in questions 1 and 2 should be submitted separately in a plain text format (.TXT) file. You may include your MySQL code also in the pdf file, for the sake of clarity, if you wish, but it should be stressed that only the code that appears in the txt file will be assessed. Make sure that you test that your MySQL code works in the version installed in the lab, because this is the version which is going to be used for the assessment.

Please write your full name and student id number on the first page of your submitted solutions.

Learning outcomes:

1.Critical understanding of the nature of relational databases.

2.Design and implement large-scale database systems.

3.Develop the ability to use SQL as a data definition and data manipulation language, and to develop a critical understanding of querying a relational database withSQL.

4.Develop a systematic understanding of transaction management and concurrency control in database systems

Assessment's purpose:

1.Create a relational database and express queries to a relational database by using SQL.

2.Check concurrency control.

3.Find the outcome for simultaneous transactions.

Total: 100 marks

Question One (30 marks)

Consider the following relational database schema,

?Book(isbn, title, publisher)

?Author(id, name)

?Writes(isbn, id)

?BookStore(bsid, address, bsName)

?Sells(bsid, isbn)

1.(8 marks) Create the above schemas in MySQL, using the CREATE TABLE statement. Make sure that you define all possible keys, and that entity integrity and referential integrity are guaranteed. Explain in detail any assumptions you may make.

2.Provide MySQL queries for the following:

(a)(2 marks) Find the addresses of all the bookstores, which sell the book with title 'Database Systems7.

(b)(3 marks) Find the titles of all the books written by 'Agatha Christie'. 0rderthe titles in ascending order

(c)(5 marks) Find the titles of the books which are written by ‘Agatha Christie' but not ‘Ian Rankin'.

(d)(6 marks) If a book is written by more than one author, those authors ‘co-authored’ this book. Find the names of the authors who have written some ‘co-authored’ books.

(e)(6 marks) List the names of the authors that wrote more than 5 books, along with the number of the books they wrote, in decreasing order of the number of books they wrote.

Hint: A good idea would be to populate sample data into your database using MySQL. This will help you to verify that your MySQL queries are correct.

Question Two (30 marks)

Consider the following relational database schema,

?Employees(eid, ename, age)

?Department (did, dname, dtype, address)

?WorksIn(eid, did, since)

?Products(pid, pname, ptype, pcolor)

?Sells(did, pid, quantity);

1.(8 marks) Create the above schemas in MySQL, using the CREATE TABLE statement. Make sure that you define all possible keys, and that entity integrity and referential integrity are guaranteed. Explain in detail any assumptions you may make.

2.Provide MySQL queries for the following:

(a)(2 marks) Find the names of departments which sell blue products.

(b)(4 marks) Find the names of departments which sell blue products and do not have any employee older than 40.

(c)(5 marks) For each department report the department-id and the age of the oldest employee working in it.

(d)(5 marks) Find the names of employees who are older than at least one employee working in department 'Central'.

(e)(6 marks) Find the names of employees working in departments which have sold at least 5 types of products.

Hint: A good idea would be to populate sample data into your database using MySQL. This will help you to verify that your MySQL queries are correct.

Question Three (26 marks)

Assume that there are three transactions T1,T2,T3 that operate (read and write) on the data items A, B, and C. We are using the following notation: RJ(X) means that the transaction TJ reads the data item X, while WJ(X) means that the transaction TJ writes on the data item X. For example R1(A) means that the transaction T1 reads the data item A, i.e., read(T1 ,A), while W3(B) would mean that the transaction T3 writes on the data item B, i.e., write(T3 ,B).

You are given the following schedules S1, S2

1.SI: R1(A),R1(B),W1(A),R2(A),R1(C),W1(C),R3(C),W2(A),R3(B),W3(A)

2.S2: R1(A),R1(B),W1(A),R2(A),W3(C),W1(C),W2(A)

For each of the above schedules

1.(5 marks) create the precedence graph of the conflicts.

SI  R1(A)W2(A) to T1->T2  W1(A)R2(A)  to T1->T2 W1(C)R3(C) to T1->T3

S2  R1(A)W2(A) to T1->T2 W1(A)R2(A) to T1->T2

2.(2 marks) show whether the schedule is conflict-serializable or not. In case it is conflict- serializable, show a corresponding serial schedule. In case it is not conflict-serializable, explain shortly why this is the case.

SI  Since the graph is acyclic schedule, a is conflict-serializable.

T3 , T1 ,T2 is the equivalent serial schedule.

T3<-T1->T2

S2 Since the graph is acyclic schedule, a is conflict-serializable.

T3 , T1 ,T2 is the equivalent serial schedule. T1->T2

3.(6 marks) can this schedule occur by use of (two-phase locking) 2PL? Explain your answer.

Question Four (14 marks)

Consider the following transactions and

TimeT1T2

1read item(A)

2A=A-2

3product = 1

4read item(A)

5write item(A)

6product = product*A

7A=A-1

8read item(B)

9write item(A)

10read item(B)

11product = product*B

12B=B+1

13write item(B)

14read item(C)

15C=C-1

16write item(C)

17read item(C)

18product = product*C product*。


At time step 0 the value of A is 3, B is 5 and C is 6.1.(10 marks) What are the values of the data items A, B and C after time step 18? What value does the "product" have?(1.'Note that "product" is a local variable of the transaction, that does not necessarily exist in the database) You should give a table, having the values of the data items at each time step, as well as the value of the local variable "product”. We assume that the local variable "product" doesn't have a value before the time step 3. Your solution should start like in the following table.

TimeABcproduct

0356n/a

1356n/a

.....(2 marks) What are the final values of the data items A, B and C if we first execute T1, and then T2 What final value does the "product" have?3.(2 marks) What are the final values of the data items A, B and C if we first execute T2 and then T1? What final value does the "product" have?


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp