Library_database_relations~_continued.xhtml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * <https://y.st./>
  4. * Copyright © 2017 Alex Yst <mailto:copyright@y.st>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org./licenses/>.
  18. **/
  19. $xhtml = array(
  20. 'title' => 'Library database relations, continued',
  21. 'subtitle' => 'Written in <span title="Databases 1">CS 2203</span> of <a href="http://www.uopeople.edu/">University of the People</a>, finalised on 2017-06-21',
  22. 'copyright year' => '2017',
  23. 'body' => <<<END
  24. <p>
  25. The entity integrity constraints are simple.
  26. First, every relation must have a primary key.
  27. This primary key must not be null and must be unique to each tuple.
  28. Semantic and domain constraints in the form of data types are listed in the lists below.
  29. With a more-complex language, we could also add constraints that, for example, required that the $a[ISBN] check sum be accurate and that the telephone number be in an acceptable format.
  30. Null and unique constraints are in the lists below as well.
  31. Remember that the telephone number of a librarian cannot be null, because the librarians are using the library&apos;s internal extension system, not their own telephones.
  32. However, a member might have a null telephone number because they might not have telephone service.
  33. </p>
  34. <p>
  35. The only foreign keys in the database are in the borrowed books relation.
  36. The borrower of a book cannot be null.
  37. If an attempt is made to remove a borrower from the database, it will be rejected if that borrower has any books checked out.
  38. The books must be turned in or removed from the library database before the member can be removed.
  39. If a book is removed from the database and it&apos;s checked out, it&apos;s tuple in the lent books table is removed by cascade too.
  40. A librarian may quit or be fired.
  41. In that case, they may be removed from the database.
  42. For keeping records straight, we should wait to remove the librarian until after any books they lent are brought back.
  43. However, we don&apos;t have to wait if we don&apos;t want to.
  44. If a librarian is removed, any books they lent out will have their librarian field nullified.
  45. </p>
  46. <h2><code>Book</code>:</h2>
  47. <p>
  48. The <code>Book</code> relation will include the following attributes in its tuples:
  49. </p>
  50. <ul>
  51. <li>
  52. <code>id</code> (integer, unique, primary key, auto-increment, not null, candidate key)
  53. </li>
  54. <li>
  55. <code>title</code> (string, not null)
  56. </li>
  57. <li>
  58. <code>author</code> (string, not null)
  59. </li>
  60. <li>
  61. <code>isbn</code> (string, not null)
  62. </li>
  63. <li>
  64. <code>publication_date</code> (string, not null)
  65. </li>
  66. <li>
  67. <code>cost</code> (float, not null)
  68. </li>
  69. </ul>
  70. <h2><code>Borrower</code>:</h2>
  71. <p>
  72. The <code>Borrower</code> relation will have the following attributes in its tuples:
  73. </p>
  74. <ul>
  75. <li>
  76. <code>card_number</code> (integer, unique, primary key, not null, candidate key)
  77. </li>
  78. <li>
  79. <code>name</code> (string, not null)
  80. </li>
  81. <li>
  82. <code>address</code> (string, not null)
  83. </li>
  84. <li>
  85. <code>postal_code</code> (integer, not null)
  86. </li>
  87. <li>
  88. <code>telephone_number</code> (string)
  89. </li>
  90. <li>
  91. <code>join_date</code> (string, not null)
  92. </li>
  93. </ul>
  94. <h2><code>BookLended</code>:</h2>
  95. <p>
  96. The tuples of the <code>BookLended</code> relation will have these attributes:
  97. </p>
  98. <ul>
  99. <li>
  100. <code>book</code> (integer, unique, primary key, foreign key, not null, candidate key)
  101. </li>
  102. <li>
  103. <code>checked_out</code> (string, not null)
  104. </li>
  105. <li>
  106. <code>due_back</code> (string, not null)
  107. </li>
  108. <li>
  109. <code>borrower</code> (integer, foreign key, not null)
  110. </li>
  111. <li>
  112. <code>librarian</code> (integer, foreign key)
  113. </li>
  114. </ul>
  115. <h2><code>Librarian</code>:</h2>
  116. <p>
  117. The attributes of the <code>Librarian</code> relation are as follows:
  118. </p>
  119. <ul>
  120. <li>
  121. <code>id</code> (integer, unique, primary key, not null, candidate key)
  122. </li>
  123. <li>
  124. <code>name</code> (string, not null)
  125. </li>
  126. <li>
  127. <code>extension</code> (integer, unique, alternate key, not null, candidate key)
  128. </li>
  129. </ul>
  130. END
  131. );