| 260 | | |
| 261 | | = Proof of Candidate Key = |
| 262 | | |
| 263 | | == Definition == |
| 264 | | |
| 265 | | A set of attributes X is a candidate key if: |
| 266 | | |
| 267 | | X⁺ = R |
| 268 | | X is minimal |
| 269 | | |
| 270 | | The closure X⁺ is computed by repeatedly applying functional dependencies until no additional attributes can be derived. |
| 271 | | |
| 272 | | == Step 1 – Testing Single Attribute Candidate Keys == |
| 273 | | |
| 274 | | === Attempt 1 === |
| 275 | | |
| 276 | | K = {attendance_id} |
| 277 | | |
| 278 | | === Closure === |
| 279 | | |
| 280 | | (attendance_id)⁺ gives: |
| 281 | | |
| 282 | | attendance_status |
| 283 | | table_number |
| 284 | | guest_id |
| 285 | | event_id |
| 286 | | |
| 287 | | Using additional dependencies: |
| 288 | | |
| 289 | | event_id → event_type, wedding_id |
| 290 | | guest_id → guest_first_name, guest_last_name, rsvp_status, wedding_id |
| 291 | | wedding_id → date, budget, notes, user_id |
| 292 | | user_id → first_name, last_name, email, phone_number, gender, birthday |
| 293 | | |
| 294 | | === Missing Dependencies === |
| 295 | | |
| 296 | | The closure still does NOT determine: |
| 297 | | |
| 298 | | venue booking information |
| 299 | | photographer booking information |
| 300 | | band booking information |
| 301 | | registrar booking information |
| 302 | | priest and church information |
| 303 | | |
| 304 | | Therefore: |
| 305 | | |
| 306 | | (attendance_id)⁺ ≠ R |
| 307 | | |
| 308 | | Conclusion: |
| 309 | | |
| 310 | | attendance_id is NOT a candidate key. |
| 311 | | |
| 312 | | == Step 2 – Testing Two Attributes == |
| 313 | | |
| 314 | | K = {attendance_id, priest_id} |
| 315 | | |
| 316 | | === Closure === |
| 317 | | |
| 318 | | Additional attributes derived: |
| 319 | | |
| 320 | | priest_name |
| 321 | | priest_contact |
| 322 | | church_id |
| 323 | | church_name |
| 324 | | church_location |
| 325 | | |
| 326 | | === Missing Dependencies === |
| 327 | | |
| 328 | | Still missing: |
| 329 | | |
| 330 | | venue booking information |
| 331 | | photographer booking information |
| 332 | | band booking information |
| 333 | | registrar booking information |
| 334 | | |
| 335 | | Therefore: |
| 336 | | |
| 337 | | (attendance_id, priest_id)⁺ ≠ R |
| 338 | | |
| 339 | | Conclusion: |
| 340 | | |
| 341 | | K is NOT a candidate key. |
| 342 | | |
| 343 | | == Step 3 – Testing Three Attributes == |
| 344 | | |
| 345 | | K = { |
| 346 | | attendance_id, |
| 347 | | venue_booking_id, |
| 348 | | photographer_booking_id |
| 349 | | } |
| 350 | | |
| 351 | | === Closure === |
| 352 | | |
| 353 | | Additional attributes derived: |
| 354 | | |
| 355 | | venue information |
| 356 | | photographer information |
| 357 | | wedding information |
| 358 | | user information |
| 359 | | |
| 360 | | === Missing Dependencies === |
| 361 | | |
| 362 | | Still missing: |
| 363 | | |
| 364 | | band booking information |
| 365 | | registrar booking information |
| 366 | | priest/church information |
| 367 | | |
| 368 | | Therefore: |
| 369 | | |
| 370 | | K⁺ ≠ R |
| 371 | | |
| 372 | | Conclusion: |
| 373 | | |
| 374 | | K is NOT a candidate key. |
| 375 | | |
| 376 | | == Step 4 – Testing Larger Attribute Sets == |
| 377 | | |
| 378 | | K = { |
| 379 | | attendance_id, |
| 380 | | priest_id, |
| 381 | | venue_booking_id, |
| 382 | | band_booking_id |
| 383 | | } |
| 384 | | |
| 385 | | === Missing Dependencies === |
| 386 | | |
| 387 | | Still missing: |
| 388 | | |
| 389 | | photographer booking information |
| 390 | | registrar booking information |
| 391 | | |
| 392 | | Therefore: |
| 393 | | |
| 394 | | K⁺ ≠ R |
| 395 | | |
| 396 | | Conclusion: |
| 397 | | |
| 398 | | K is NOT a candidate key. |
| 399 | | |
| 400 | | == Step 5 – Including All Booking Branches == |
| 401 | | |
| 402 | | K = { |
| 403 | | attendance_id, |
| 404 | | venue_booking_id, |
| 405 | | photographer_booking_id, |
| 406 | | band_booking_id, |
| 407 | | registrar_booking_id |
| 408 | | } |
| 409 | | |
| 410 | | === Missing Dependencies === |
| 411 | | |
| 412 | | Still missing: |
| 413 | | |
| 414 | | priest information |
| 415 | | church information |
| 416 | | |
| 417 | | Therefore: |
| 418 | | |
| 419 | | K⁺ ≠ R |
| 420 | | |
| 421 | | Conclusion: |
| 422 | | |
| 423 | | K is NOT a candidate key. |
| 424 | | |
| 425 | | == Step 6 – Final Candidate Key == |
| 426 | | |
| 427 | | K = { |
| 428 | | attendance_id, |
| 429 | | venue_booking_id, |
| 430 | | photographer_booking_id, |
| 431 | | band_booking_id, |
| 432 | | registrar_booking_id, |
| 433 | | priest_id |
| 434 | | } |
| 435 | | |
| 436 | | === Closure === |
| 437 | | |
| 438 | | Using all functional dependencies: |
| 439 | | |
| 440 | | attendance branch is determined |
| 441 | | event branch is determined |
| 442 | | guest branch is determined |
| 443 | | wedding branch is determined |
| 444 | | venue booking branch is determined |
| 445 | | photographer booking branch is determined |
| 446 | | band booking branch is determined |
| 447 | | registrar booking branch is determined |
| 448 | | priest branch is determined |
| 449 | | church branch is determined |
| 450 | | |
| 451 | | No attributes remain undetermined. |
| 452 | | |
| 453 | | Therefore: |
| 454 | | |
| 455 | | K⁺ = R |
| 456 | | |
| 457 | | Conclusion: |
| 458 | | |
| 459 | | K is a candidate key. |
| 460 | | |
| 461 | | == Minimality Proof == |
| 462 | | |
| 463 | | A candidate key must be minimal. |
| 464 | | |
| 465 | | Removing any attribute from K causes loss of at least one independent entity branch: |
| 466 | | |
| 467 | | || Removed Attribute || Lost Information || |
| 468 | | || attendance_id || attendance branch || |
| 469 | | || venue_booking_id || venue booking branch || |
| 470 | | || photographer_booking_id || photographer booking branch || |
| 471 | | || band_booking_id || band booking branch || |
| 472 | | || registrar_booking_id || registrar booking branch || |
| 473 | | || priest_id || priest/church branch || |
| 474 | | |
| 475 | | Therefore every attribute in K is necessary. |
| 476 | | |
| 477 | | == Why church_id Is Not Included == |
| 478 | | |
| 479 | | Suppose we define: |
| 480 | | |
| 481 | | K = { |
| 482 | | attendance_id, |
| 483 | | venue_booking_id, |
| 484 | | photographer_booking_id, |
| 485 | | band_booking_id, |
| 486 | | registrar_booking_id, |
| 487 | | priest_id, |
| 488 | | church_id |
| 489 | | } |
| 490 | | |
| 491 | | This violates minimality because: |
| 492 | | |
| 493 | | priest_id → church_id |
| 494 | | |
| 495 | | church_id is already derivable from priest_id. |
| 496 | | |
| 497 | | Therefore church_id is redundant. |
| 498 | | |
| 499 | | The resulting set would be a superkey, NOT a candidate key. |
| 500 | | |
| 501 | | == Final Candidate Key == |
| 502 | | |
| 503 | | K = { |
| 504 | | attendance_id, |
| 505 | | venue_booking_id, |
| 506 | | photographer_booking_id, |
| 507 | | band_booking_id, |
| 508 | | registrar_booking_id, |
| 509 | | priest_id |
| 510 | | } |
| 511 | | |
| 512 | | This key: |
| 513 | | |
| 514 | | Determines all attributes of R |
| 515 | | Is minimal |
| 516 | | Satisfies the formal definition of a candidate key |