| 1 | | == Candidate Key Determination == |
| 2 | | |
| 3 | | As mentioned before, based on business rules of the Wedding Planner system, the following functional dependencies hold: |
| 4 | | |
| 5 | | || ID || Functional Dependency || Justification || |
| 6 | | || FD1 || user_id → user_first_name, user_last_name, user_email || User attributes depend only on user_id |
| 7 | | || FD2 || wedding_id → wedding_date, wedding_budget, user_id || A wedding uniquely defines its properties |
| 8 | | || FD3 || venue_id → venue_name, venue_type, venue_capacity || Venue attributes depend only on venue_id |
| 9 | | || FD4 || booking_id → venue_id, wedding_id, booking_date, start_time, end_time || A booking uniquely defines a venue reservation || |
| 10 | | === FD1: user_id → user_first_name, user_last_name, user_email === |
| 11 | | |
| 12 | | Proof: |
| 13 | | |
| 14 | | || Condition || Reason || |
| 15 | | || user_id is unique || Each user has exactly one system account |
| 16 | | || Name and email belong to the user || They do not depend on weddings or venues |
| 17 | | || Same user_id always gives same values || No variation allowed by system rules |
| 18 | | |
| 19 | | Conclusion: |
| 20 | | |
| 21 | | || Functional Dependency || |
| 22 | | || user_id → user_first_name, user_last_name, user_email || |
| 23 | | |
| 24 | | This dependency is non-transitive and deterministic. |
| 25 | | |
| 26 | | === FD2: wedding_id → wedding_date, wedding_budget, user_id === |
| 27 | | |
| 28 | | Proof: |
| 29 | | |
| 30 | | || Condition || Reason || |
| 31 | | || wedding_id is unique || Each wedding is registered once |
| 32 | | || Wedding date is fixed || A wedding cannot have multiple dates |
| 33 | | || Budget belongs to the wedding || Independent of venue choice |
| 34 | | || Each wedding has one owner || user_id identifies the organizer |
| 35 | | |
| 36 | | Conclusion: |
| 37 | | |
| 38 | | || Functional Dependency || |
| 39 | | || wedding_id → wedding_date, wedding_budget, user_id || |
| 40 | | |
| 41 | | This shows entity integrity for weddings. |
| 42 | | |
| 43 | | === FD3: venue_id → venue_name, venue_type, venue_capacity === |
| 44 | | |
| 45 | | Proof: |
| 46 | | |
| 47 | | || Condition || Reason || |
| 48 | | || venue_id is unique || One ID per physical venue |
| 49 | | || Name and type are static || Do not change per booking |
| 50 | | || Capacity is venue-specific || Independent of weddings |
| 51 | | |
| 52 | | Conclusion: |
| 53 | | |
| 54 | | || Functional Dependency || |
| 55 | | || venue_id → venue_name, venue_type, venue_capacity || |
| 56 | | |
| 57 | | Venue attributes are fully functionally dependent on venue_id. |
| 58 | | |
| 59 | | === FD4: booking_id → venue_id, wedding_id, booking_date, start_time, end_time === |
| 60 | | |
| 61 | | Proof: |
| 62 | | |
| 63 | | || Condition || Reason || |
| 64 | | || booking_id is unique || One booking per reservation |
| 65 | | || Booking ties venue and wedding || Both are required |
| 66 | | || Date and time define reservation || Cannot vary per booking || |
| 67 | | |
| 68 | | Conclusion: |
| 69 | | |
| 70 | | || Functional Dependency || |
| 71 | | || booking_id → venue_id, wedding_id, booking_date, start_time, end_time || |
| 72 | | |
| 73 | | This models a relationship entity (association table). |
| 74 | | |
| 75 | | == Step 3: Attribute Closure Calculation == |
| 76 | | |
| 77 | | To find a candidate key, we compute attribute closures. |
| 78 | | |
| 79 | | === Attempt 1: user_id⁺ === |
| 80 | | |
| 81 | | || Derived Attributes || |
| 82 | | || user_first_name, user_last_name, user_email || |
| 83 | | |
| 84 | | ❌ Does NOT determine wedding, venue, or booking data |
| 85 | | → Not a key |
| 86 | | |
| 87 | | === Attempt 2: wedding_id⁺ === |
| 88 | | |
| 89 | | || Derived Attributes || |
| 90 | | || wedding_date, wedding_budget, user_id, user_first_name, user_last_name, user_email || |
| 91 | | |
| 92 | | ❌ Missing venue and booking data |
| 93 | | → Not a key |
| 94 | | |
| 95 | | === Attempt 3: venue_id⁺ === |
| 96 | | |
| 97 | | || Derived Attributes || |
| 98 | | || venue_name, venue_type, venue_capacity || |
| 99 | | |
| 100 | | ❌ Missing user, wedding, booking |
| 101 | | → Not a key |
| 102 | | |
| 103 | | === Attempt 4: booking_id⁺ === |
| 104 | | |
| 105 | | || Derived Attributes || |
| 106 | | || venue_id, wedding_id, booking_date, start_time, end_time || |
| 107 | | || venue_name, venue_type, venue_capacity || |
| 108 | | || wedding_date, wedding_budget, user_id || |
| 109 | | || user_first_name, user_last_name, user_email || |
| 110 | | |
| 111 | | ✅ booking_id⁺ = ALL ATTRIBUTES |
| 112 | | |
| 113 | | Thus: |
| 114 | | |
| 115 | | || Candidate Key || |
| 116 | | || booking_id || |
| 117 | | |
| 118 | | To uniquely identify a tuple in R, the following composite key is required: |
| 119 | | |
| 120 | | || Candidate Key || |
| 121 | | || (user_id, wedding_id, venue_id, booking_date) || |
| 122 | | |
| 123 | | This confirms that the initial relation has a composite primary key, which leads to partial dependencies. |
| | 1 | = Proof of Candidate Key = |
| | 2 | |
| | 3 | == Definition == |
| | 4 | |
| | 5 | A set of attributes X is a candidate key if: |
| | 6 | |
| | 7 | X⁺ = R |
| | 8 | X is minimal |
| | 9 | |
| | 10 | The closure X⁺ is computed by repeatedly applying functional dependencies until no additional attributes can be derived. |
| | 11 | |
| | 12 | == Step 1 – Testing Single Attribute Candidate Keys == |
| | 13 | |
| | 14 | === Attempt 1 === |
| | 15 | |
| | 16 | K = {attendance_id} |
| | 17 | |
| | 18 | === Closure === |
| | 19 | |
| | 20 | (attendance_id)⁺ gives: |
| | 21 | |
| | 22 | attendance_status |
| | 23 | table_number |
| | 24 | guest_id |
| | 25 | event_id |
| | 26 | |
| | 27 | Using additional dependencies: |
| | 28 | |
| | 29 | event_id → event_type, wedding_id |
| | 30 | guest_id → guest_first_name, guest_last_name, rsvp_status, wedding_id |
| | 31 | wedding_id → date, budget, notes, user_id |
| | 32 | user_id → first_name, last_name, email, phone_number, gender, birthday |
| | 33 | |
| | 34 | === Missing Dependencies === |
| | 35 | |
| | 36 | The closure still does NOT determine: |
| | 37 | |
| | 38 | venue booking information |
| | 39 | photographer booking information |
| | 40 | band booking information |
| | 41 | registrar booking information |
| | 42 | priest and church information |
| | 43 | |
| | 44 | Therefore: |
| | 45 | |
| | 46 | (attendance_id)⁺ ≠ R |
| | 47 | |
| | 48 | Conclusion: |
| | 49 | |
| | 50 | attendance_id is NOT a candidate key. |
| | 51 | |
| | 52 | == Step 2 – Testing Two Attributes == |
| | 53 | |
| | 54 | K = {attendance_id, priest_id} |
| | 55 | |
| | 56 | === Closure === |
| | 57 | |
| | 58 | Additional attributes derived: |
| | 59 | |
| | 60 | priest_name |
| | 61 | priest_contact |
| | 62 | church_id |
| | 63 | church_name |
| | 64 | church_location |
| | 65 | |
| | 66 | === Missing Dependencies === |
| | 67 | |
| | 68 | Still missing: |
| | 69 | |
| | 70 | venue booking information |
| | 71 | photographer booking information |
| | 72 | band booking information |
| | 73 | registrar booking information |
| | 74 | |
| | 75 | Therefore: |
| | 76 | |
| | 77 | (attendance_id, priest_id)⁺ ≠ R |
| | 78 | |
| | 79 | Conclusion: |
| | 80 | |
| | 81 | K is NOT a candidate key. |
| | 82 | |
| | 83 | == Step 3 – Testing Three Attributes == |
| | 84 | |
| | 85 | K = { |
| | 86 | attendance_id, |
| | 87 | venue_booking_id, |
| | 88 | photographer_booking_id |
| | 89 | } |
| | 90 | |
| | 91 | === Closure === |
| | 92 | |
| | 93 | Additional attributes derived: |
| | 94 | |
| | 95 | venue information |
| | 96 | photographer information |
| | 97 | wedding information |
| | 98 | user information |
| | 99 | |
| | 100 | === Missing Dependencies === |
| | 101 | |
| | 102 | Still missing: |
| | 103 | |
| | 104 | band booking information |
| | 105 | registrar booking information |
| | 106 | priest/church information |
| | 107 | |
| | 108 | Therefore: |
| | 109 | |
| | 110 | K⁺ ≠ R |
| | 111 | |
| | 112 | Conclusion: |
| | 113 | |
| | 114 | K is NOT a candidate key. |
| | 115 | |
| | 116 | == Step 4 – Testing Larger Attribute Sets == |
| | 117 | |
| | 118 | K = { |
| | 119 | attendance_id, |
| | 120 | priest_id, |
| | 121 | venue_booking_id, |
| | 122 | band_booking_id |
| | 123 | } |
| | 124 | |
| | 125 | === Missing Dependencies === |
| | 126 | |
| | 127 | Still missing: |
| | 128 | |
| | 129 | photographer booking information |
| | 130 | registrar booking information |
| | 131 | |
| | 132 | Therefore: |
| | 133 | |
| | 134 | K⁺ ≠ R |
| | 135 | |
| | 136 | Conclusion: |
| | 137 | |
| | 138 | K is NOT a candidate key. |
| | 139 | |
| | 140 | == Step 5 – Including All Booking Branches == |
| | 141 | |
| | 142 | K = { |
| | 143 | attendance_id, |
| | 144 | venue_booking_id, |
| | 145 | photographer_booking_id, |
| | 146 | band_booking_id, |
| | 147 | registrar_booking_id |
| | 148 | } |
| | 149 | |
| | 150 | === Missing Dependencies === |
| | 151 | |
| | 152 | Still missing: |
| | 153 | |
| | 154 | priest information |
| | 155 | church information |
| | 156 | |
| | 157 | Therefore: |
| | 158 | |
| | 159 | K⁺ ≠ R |
| | 160 | |
| | 161 | Conclusion: |
| | 162 | |
| | 163 | K is NOT a candidate key. |
| | 164 | |
| | 165 | == Step 6 – Final Candidate Key == |
| | 166 | |
| | 167 | K = { |
| | 168 | attendance_id, |
| | 169 | venue_booking_id, |
| | 170 | photographer_booking_id, |
| | 171 | band_booking_id, |
| | 172 | registrar_booking_id, |
| | 173 | priest_id |
| | 174 | } |
| | 175 | |
| | 176 | === Closure === |
| | 177 | |
| | 178 | Using all functional dependencies: |
| | 179 | |
| | 180 | attendance branch is determined |
| | 181 | event branch is determined |
| | 182 | guest branch is determined |
| | 183 | wedding branch is determined |
| | 184 | venue booking branch is determined |
| | 185 | photographer booking branch is determined |
| | 186 | band booking branch is determined |
| | 187 | registrar booking branch is determined |
| | 188 | priest branch is determined |
| | 189 | church branch is determined |
| | 190 | |
| | 191 | No attributes remain undetermined. |
| | 192 | |
| | 193 | Therefore: |
| | 194 | |
| | 195 | K⁺ = R |
| | 196 | |
| | 197 | Conclusion: |
| | 198 | |
| | 199 | K is a candidate key. |
| | 200 | |
| | 201 | == Minimality Proof == |
| | 202 | |
| | 203 | A candidate key must be minimal. |
| | 204 | |
| | 205 | Removing any attribute from K causes loss of at least one independent entity branch: |
| | 206 | |
| | 207 | || Removed Attribute || Lost Information || |
| | 208 | || attendance_id || attendance branch || |
| | 209 | || venue_booking_id || venue booking branch || |
| | 210 | || photographer_booking_id || photographer booking branch || |
| | 211 | || band_booking_id || band booking branch || |
| | 212 | || registrar_booking_id || registrar booking branch || |
| | 213 | || priest_id || priest/church branch || |
| | 214 | |
| | 215 | Therefore every attribute in K is necessary. |
| | 216 | |
| | 217 | == Why church_id Is Not Included == |
| | 218 | |
| | 219 | Suppose we define: |
| | 220 | |
| | 221 | K = { |
| | 222 | attendance_id, |
| | 223 | venue_booking_id, |
| | 224 | photographer_booking_id, |
| | 225 | band_booking_id, |
| | 226 | registrar_booking_id, |
| | 227 | priest_id, |
| | 228 | church_id |
| | 229 | } |
| | 230 | |
| | 231 | This violates minimality because: |
| | 232 | |
| | 233 | priest_id → church_id |
| | 234 | |
| | 235 | church_id is already derivable from priest_id. |
| | 236 | |
| | 237 | Therefore church_id is redundant. |
| | 238 | |
| | 239 | The resulting set would be a superkey, NOT a candidate key. |
| | 240 | |
| | 241 | == Final Candidate Key == |
| | 242 | |
| | 243 | K = { |
| | 244 | attendance_id, |
| | 245 | venue_booking_id, |
| | 246 | photographer_booking_id, |
| | 247 | band_booking_id, |
| | 248 | registrar_booking_id, |
| | 249 | priest_id |
| | 250 | } |
| | 251 | |
| | 252 | This key: |
| | 253 | |
| | 254 | Determines all attributes of R |
| | 255 | Is minimal |
| | 256 | Satisfies the formal definition of a candidate key |