ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

COMPSCI 351 Model Solutions

2021-06-11 09:05:25  阅读:228  来源: 互联网

标签:Case cid lname lno COMPSCI Solutions Lawyer marks Model


StudentName: COMPSCI 351

TEST 1 - Model Solutions
SECOND SEMESTER 2020/2021
COMPUTER SCIENCE
Fundamentals of Database Systems
Time Allowed: FORTY FIVE (45) minutes
NOTE:
– The test is closed book.
– No calculators are permitted.
– Attempt ALL questions in this test.
– A maximum of 30 marks is available in this test.
1

  1. The Relational Model of Data.
    (a) Consider the relation schema Client. It stores the client number cid, the client name
    cname and client birthday cbday. Which superkeys does the following relation over
    Client satisfy? [3 marks]
    cid cname cbday
  2. Catherine 01/02/1990
  3. Catherine 03/04/1986
  4. Caleb 03/04/1986
    Solution (1 mark for the two keys; 1 mark for the three proper superkeys; 1 mark if
    nothing else has been defined):
    – {cid},
    – {cid,cname},
    – {cid,cbday},
    – {cid,cname,cbday},
    – {cname,cbday}
    (b) Consider the relation schema Lawyer. It stores the number lno and name lname of
    a lawyer, and the practice lpractice the lawyer works in. Write down a single relation
    over Lawyer that
    – satisfies the two keys {lno,lname} and {lname,lpractice},
    – violates all superkeys not contained in the keys above, and
    – has as few tuples as possible. [4 marks]
    One solution (1 mark for violating {lname}, 1 mark for violating {lno,lpractice}, 1
    mark for satisfying the keys, 1 mark for not introducing anything else):
    lno lname lpractice
  5. Harvey Pearson
  6. Harvey Specter Litt
  7. Mike Specter Litt
    (c) Consider the relation schema Laywer from before, as well as the relation schema
    Partner with attributes pno, pname, and psince, expressing which year a lawyer has
    been a partner since. Write down a single relation over Lawyer and a single relation
    over Partner that
    – satisfy the foreign keys [pno]⊆Lawyer[lno] and [pname]⊆Lawyer[lname] on
    Partner, and
    – do not satisfy Partner[pno,pname]⊆Lawyer[lno,lname] (inclusion dependency)
    which requires for each tuple t over Partner a tuple t
  8. over Lawyer such that
    t[pno, pname] = t
    0
    [lno, lname] holds, and
    – each have as few tuples as possible. [3 marks]
    One solution (1 mark for each of the bullet points above)
    Partner
    pno pname psince
  9. Harvey 2011
    Lawyer
    lno lname lpractice
  10. Mike Pearson
  11. Harvey Pearson
    2
  12. SQL. Consider the relational database schema {Client, Lawyer, Case} as given below:
    – Client={cid, cname, cbday} with key {cid}
    – Lawyer={lno, lname, lpractice} with key {lno}
    – Case={cid, lno, date, verdict} with key {cid, lno, date} and foreign keys
    • [cid] ⊆ Client[cid]
    • [lno] ⊆ Lawyer[lno].
    (a) Write an English language description of the following query:
    SELECT c.lno, c.date, COUNT(c.id) AS number of cases
    FROM Case c
    WHERE c.verdict <> ‘guilty’
    GROUP BY c.lno, c.date
    HAVING COUNT(∗) >= 2;
    [4 marks]
    Solution (1 mark each):
    – For each lno and date, what is the number of cases
    – a lawyer with the lno has represented on the date
    – where the verdict is different from guilty
    – and provided there were at least two cases?
    (b) Write the following query in SQL: What is the id of clients that had all their cases
    handled by lawyers named Annalise or Annamae? [3 marks]
    Solution (1 mark for the first two lines, 2 marks for the sub-query including all the
    conditions in the WHERE clause):
    SELECT c.cid
    FROM Case c
    WHERE NOT EXISTS ( SELECT ∗
    FROM Case c1, Lawyer l
    WHERE c.cid=c1.cid AND c1.lno=l.lno AND
    l.lname <> ‘Annamae’ AND l.lname <> ‘Annalise’ ) ;
    (c) Write the following query in SQL: What are the names of clients that were represented
    by at least two different lawyers from Pearson on the same day? [3 marks]
    Solution (several different solutions possible; 1 mark for correct join; 1.5 marks for the
    correct conditions in the WHERE clause; 0.5 marks for correct attribute in the SELECT
    clause):
    SELECT c.cname
    FROM Case c1, Case c2, Client c, Lawyer l1, Lawyer l2
    WHERE c1.cid=c.cid AND c2.cid=c.cid AND c1.lno=l1.lno AND
    c2.lno=l2.lno AND l1.lpractice=‘Pearson’ AND
    l2.lpractice=‘Pearson’ AND c1.date=c2.date AND c1.lno <> c2.lno;
    3
  13. Relational algebra. Consider the relational database schema {Client, Lawyer, Case}
    as given below:
    – Client={cid, cname, cbday} with key {cid}
    – Lawyer={lno, lname, lpractice} with key {lno}
    – Case={cid, lno, date, verdict} with key {cid, lno, date} and foreign keys
    • [cid] ⊆ Client[cid]
    • [lno] ⊆ Lawyer[lno].
    Write relational algebra queries using only operators defined on the lecture slides.
    (a) Write an English language description of the following query:
    πdate,lno(σverdict=guilty(Case)) ÷ πlno(σlpractice=Pearson(Lawyer))
    [3 marks]
    Solution (1 mark each):
    – What are the dates on which
    – every lawyer that works in the practice Pearson
    – is involved in some case with verdict guilty?
    (b) Write in relational algebra: What is the id of clients that had all their cases handled
    by lawyers named Annalise or Annamae? [3 marks]
    Solution (1 mark each):
    – Q1 = πlno(σlname=‘Annalise’(Lawyer) ∪ σlname=‘Annamae’(Lawyer))
    – Q2 = πcid(Case − (Q1 ./ Case))
    – Q3 = πcid(Client) − Q2
    (c) Write in relational algebra: What are the names of clients that were represented
    by at least two different lawyers from Pearson on the same day? [4 marks]
    Solution (1 mark each):
    – Q1 = δlno7→lno0
    ,verdict7→verdict0(Case) ./ Case ./ σlpractice=‘Pearson’(Lawyer)
    – Q2 = Q1 − σlno=lno0(Q1)
    – Q3 = πcid(Q2) ./ Client
    – Q4 = πcname(Q3)
    WX:codehelp

标签:Case,cid,lname,lno,COMPSCI,Solutions,Lawyer,marks,Model
来源: https://www.cnblogs.com/ipython258/p/14873659.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有