Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.55 KB | None | 0 0
  1. Question 1.
  2. i.
  3. a)
  4.  
  5. If we delete a row from table Staff_Branch for example row 4, StaffID S333, BranchID B33 the other information about that branch are also deleted from the database as well e.g. Br_Address 21 Faker Road.
  6.  
  7. Y /a
  8. select P_code, V_name
  9. from PRODUCT p inner join VENDOR v
  10. on p.V_CODE = v.V_CODE;
  11.  
  12. Y / c
  13. select Order_code, COUNT (P_PRICE) AS 'Total cost'
  14. from ORDER_DETAIL od inner join PRODUCT P
  15. on od.Product_CODE = p.P_CODE
  16. group by Order_code;
  17.  
  18.  
  19.  
  20. ii.
  21.  
  22.  
  23. iii.
  24. b)
  25. select DISTINCT firstName, lastName
  26. from [Owner] o inner join PetAndOwner pao
  27. on o.ownerId = pao.ownerId inner join Pet p
  28. on p.petId = pao.petId inner join PetType pt
  29. on p.petTypeId = pt.petTypeId
  30. where animalType ='dog';
  31.  
  32. iv.
  33. a)
  34. ACID Stands for
  35. A - Atomicity
  36. C - Consistency
  37. I - Isolation
  38. D - Durability
  39.  
  40. Isolation
  41. The isolation property ensures that the concurrent execution of transaction results in a system state that would be obtained if transaction were executed sequentially, one after the other.
  42. Example of ACID (I)
  43. A teller looking up a balance must be isolated from a concurrent transaction involving a withdrawal from the same account. Only when the withdrawal transaction commits successfully and the teller looks at the balance again will the new balance be reported.
  44. You go to the bank, your current balance is $100, you withdraw $20 from the same account, only when the withdrawal transaction how been completed successfully and the banker looks at your balance again, will the new balance be reported.
  45.  
  46. b)
  47. select firstName, lastName, petName
  48. from [Owner] o LEFT OUTER join PetAndOwner pao
  49. on o.ownerId = pao.ownerId
  50. LEFT OUTER join Pet p
  51. on p.petId = pao.petId;
  52. Question 2.
  53.  
  54. i.
  55. ER Diagram
  56.  
  57.  
  58. ii.
  59. GRD
  60.  
  61.  
  62.  
  63. Question 3.
  64. Create Statements
  65. i.
  66.  
  67. CREATE TABLE Training (
  68. trainingID numeric(8) NOT NULL,
  69. trainingType varchar(20) NOT NULL,
  70. CONSTRAINT Training_PK PRIMARY KEY (trainingID)
  71. );
  72.  
  73. CREATE TABLE Coach (
  74. coachID numeric(8) NOT NULL,
  75. coachName varchar(20) NOT NULL,
  76. coachEmail varchar(20) NOT NULL,
  77. coachTele numeric(8) NOT NULL,
  78. coachAddress varchar(20) NOT NULL,
  79. coachPostcode numeric(4) NOT NULL,
  80. CONSTRAINT Coach_PK PRIMARY KEY (coachID)
  81. );
  82.  
  83. CREATE TABLE Achievements (
  84. qualifications varchar(20) NOT NULL,
  85. [certificates] varchar(20) NOT NULL,
  86. awards varchar(20) NOT NULL,
  87. yearOfConferment numeric(4) NOT NULL,
  88. coachID numeric(8) NOT NULL,
  89. CONSTRAINT Achievements_qualifications_PK PRIMARY KEY (qualifications),
  90. CONSTRAINT Achievements_coachID_FK FOREIGN KEY (coachID) REFERENCES Coach
  91. );
  92.  
  93. CREATE TABLE Venue (
  94. venueID numeric(8) NOT NULL,
  95. venueName varchar(20) NOT NULL,
  96. venueTele numeric(8) NOT NULL,
  97. venueAddress varchar(20) NOT NULL,
  98. venuePostcode numeric(4) NOT NULL,
  99. bookingID numeric(8) NOT NULL,
  100. CONSTRAINT Venue_PK PRIMARY KEY (venueID)
  101. );
  102.  
  103. CREATE TABLE Client (
  104. clientID numeric(8) NOT NULL,
  105. clientName varchar(20) NOT NULL,
  106. clientEmail varchar(20) NOT NULL,
  107. clientTele numeric(8) NOT NULL,
  108. clientAddress varchar(20) NOT NULL,
  109. clientPostcode numeric(4) NOT NULL,
  110. CONSTRAINT Client_clientID_PK PRIMARY KEY (clientID)
  111. );
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. CREATE TABLE Booking (
  126. bookingID numeric(8) NOT NULL,
  127. dateOfBooking date NOT NULL,
  128. timeofBooking datetime NOT NULL,
  129. sessionDuration varchar(20) NOT NULL,
  130. amountDue varchar(20) NOT NULL,
  131. amountPaid varchar(20) NOT NULL,
  132. paymentStatus varchar(20) NOT NULL,
  133. completionStatus varchar(20) NOT NULL,
  134. coachID numeric(8) NOT NULL,
  135. clientID numeric(8) NOT NULL,
  136. trainingID numeric(8) NOT NULL,
  137. venueID numeric(8) NOT NULL,
  138. CONSTRAINT Booking_bookingID_PK PRIMARY KEY (bookingID),
  139. CONSTRAINT Booking_coachID_FK FOREIGN KEY (coachID) REFERENCES Coach,
  140. CONSTRAINT Booking_clientID_FK FOREIGN KEY (clientID) REFERENCES Client,
  141. CONSTRAINT Booking_trainingID_FK FOREIGN KEY (trainingID) REFERENCES Training,
  142. CONSTRAINT Booking_venueID_FK FOREIGN KEY (venueID) REFERENCES Venue
  143. );
  144.  
  145. Insert Statements
  146. INSERT INTO Training VALUES ('1','Mathematics');
  147. INSERT INTO Training VALUES ('2','Physics');
  148. INSERT INTO Training VALUES ('3','Swimming');
  149. INSERT INTO Training VALUES ('4','Tennis');
  150. INSERT INTO Training VALUES ('5','Latin Dancing');
  151. INSERT INTO Training VALUES ('6','Ballet');
  152.  
  153. INSERT INTO Coach VALUES ('111','Ash','ashthecoach@mail.com','95552775','21 Star Road','2170');
  154. INSERT INTO Coach VALUES ('222','Vatche','vatche@mail.com','95556576','98 Berry Road','2770');
  155. INSERT INTO Coach VALUES ('333','Moe','moe@mail.com','95551221','4 Crickle Road','2210');
  156.  
  157. INSERT INTO Achievements VALUES ('Leadership Skills','PHD Science','Science Award','1998','111');
  158. INSERT INTO Achievements VALUES ('Team Manager','PHD Sport','Sports Award','1989','222');
  159. INSERT INTO Achievements VALUES ('Great Communication','PHD Drama','Drama Award','2011','333');
  160.  
  161. INSERT INTO Venue VALUES ('1','Science Centre','98772341','23 Cluckin Road','2345','1');
  162. INSERT INTO Venue VALUES ('2','Sports Centre','98779310','4 Shayle Road','2781','2');
  163. INSERT INTO Venue VALUES ('3','Dance Academy','98774832','69 Beandere Street','2211','3');
  164.  
  165. INSERT INTO Client VALUES ('1','Baron','nashor@mail.com','92221010','27 Yemoite Avenue','2333');
  166. INSERT INTO Client VALUES ('2','Herald','rift@mail.com','92229889','58 Holla Cresent','2211');
  167. INSERT INTO Client VALUES ('3','Fem','Inist@mail.com','92221234','76 Genders Road','2999');
  168.  
  169. INSERT INTO Booking VALUES ('1','2015-02-10','2015-02-10 12:30','2 Hours','$80','$80','Paid','Yes','111','1','1','1');
  170. INSERT INTO Booking VALUES ('2','2015-03-10','2015-03-10 14:30','2 Hours','$80','$80','Paid','Yes','222','2','3','2');
  171. INSERT INTO Booking VALUES ('3','2015-04-10','2015-04-10 16:30','2 Hours','$80','$80','Paid','Yes','333','3','5','3');
  172.  
  173.  
  174. ii.
  175. -- Question 3
  176. -- ii.
  177. -- a)
  178. select coachName, dateOfBooking
  179. from Coach c inner join Booking b
  180. on c.coachID = b.coachID
  181. where coachName LIKE 'Ash'
  182. AND dateOfBooking = '2015-02-10';
  183.  
  184. --b)
  185. select coachName, COUNT (sessionDuration) AS 'Total number of Hours'
  186. from Coach c inner join Booking b
  187. on c.coachID = b.coachID
  188. group by coachName;
  189.  
  190. --c)
  191. select coachName, timeOfBooking, venueName, clientName
  192. from Coach c inner join Booking b
  193. on c.coachID = b.coachID
  194. inner join venue v on b.venueID = v.venueID
  195. inner join Client on b.clientID = Client.clientID
  196. where dateOfBooking = '2015-02-10'
  197. group by coachName, timeOfBooking, venueName, clientName;
  198.  
  199.  
  200. --d)
  201. select coachName
  202. from Coach c full Outer join Booking b
  203. on c.coachID = b.coachID
  204. inner join Training t on t.trainingID = b.bookingID
  205. WHERE dateofBooking = '2015-02-10 12:30'
  206. AND trainingType = 'Mathematics';
  207.  
  208.  
  209.  
  210.  
  211. iii.)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement