1. Home
  2. Explore
  3. Computer Science
  4. Foreign Keys and Referential Integrity

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Foreign Keys and Referential Integrity

  • 68Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Integrity Constraints
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is a foreign key?

Tap to flipClick to flipspace

A group of attributes in one relation used to refer to tuples in another relation.

Or swipe the card

68 cards

  1. What is a foreign key?

    A group of attributes in one relation used to refer to tuples in another relation.

  2. What does a referential integrity constraint require?

    Every foreign-key value must refer to an existing tuple in the referenced relation; it must not create a dangling reference.

  3. What values may a foreign key contain under the described constraint?

    It may be null or contain values that exist in the referenced relation's corresponding key column.

  4. Must a foreign-key attribute have the same name as the referenced attribute?

    No. Foreign-key and referenced attributes may have different names, such as department number and department Id.

  5. Which attribute in student refers to the department relation?

    department number is a foreign key referring to the department identifier.

  6. Which attribute in student identifies the student's advisor?

    advisor is a foreign key referring to the employee ID of a professor.

  7. Which attribute in department identifies its head of department?

    hod is a foreign key referring to the employee ID of a professor.

  8. Which attributes in prerequisite reference the course relation?

    Both preReqCourse and course Id are foreign keys referring to the course ID.

  9. Which attributes in enrollment are foreign keys?

    roll number refers to student, and course Id refers to course.

  10. Which attributes in professor, course, and teaching reference other relations?

    Professor's department number refers to department; course's department number refers to department; teaching's employee Id and course Id refer to professor and course, respectively.

  11. What does underlining an attribute or group of attributes in a relational schema indicate?

    It indicates that the attribute or group is a key.

  12. What is the key of the student relation, and why?

    roll number; its value uniquely identifies each student tuple.

  13. What does a key guarantee about tuples in a relation?

    No two tuples have the same value for the key.

  14. What attributes belong to the student relation?

    roll number, name, degree, years, sex, department number, and advisor.

  15. What does the degree attribute in student represent?

    The academic program in which the student is enrolled.

  16. What does the years attribute in student represent?

    The student's year of admission.

  17. What information is stored in the department relation?

    department Id, name, hod, and phone.

  18. Why is department Id used as a key instead of the department name?

    A numeric department ID is chosen to make departments easily identifiable, even though the name could also serve as a key.

  19. What does hod represent in the department relation?

    The faculty member who heads and is academically responsible for running the department.

  20. What attributes belong to the professor relation?

    employee Id, name, sex, start year, department number, and phone number.

  21. What does start year mean in the professor relation?

    The year in which the faculty member joined the department.

  22. What attributes belong to the course relation?

    course Id, c name, credits, and department number.

  23. What does c name represent in the course relation?

    The name of the course.

  24. What does the credits attribute represent?

    The number of credits earned by successfully completing the course.

  25. What is the key of the course relation?

    course Id.

  26. What does the enrollment relation record?

    Which students enroll in which courses, in which semester and year, and the grade they receive.

  27. What is the key of the enrollment relation?

    The combination of roll number, course Id, semester, and year.

  28. Why is course Id alone insufficient as the key of enrollment?

    A course is offered multiple times and can have many enrolled students.

  29. Why are semester and year part of the enrollment key?

    They identify the particular offering of a course in which the student enrolled.

  30. What values can semester take in the enrollment relation?

    odd or even, representing the August and January semesters, respectively.

  31. What value does grade have during the current semester?

    Null.

  32. What does the teaching relation record?

    Which professor teaches which course in a particular semester and year, including the classroom.

  33. What is the key of the teaching relation?

    The combination of employee Id, course Id, semester, and year.

  34. Why is employee Id alone not a key of teaching?

    A professor may teach several courses over the course of employment.

  35. Why is course Id alone not a key of teaching?

    A course may be taught by several professors and offered in different semesters and years.

  36. What does a tuple (C1,C2)(C_1, C_2)(C1​,C2​) in prerequisite mean?

    C1C_1C1​ must be successfully completed before a student enrolls in C2C_2C2​.

  37. Give an example of a prerequisite relationship from the schema.

    Data Structures may be a prerequisite for Database Systems.

  38. What is a relational schema diagram?

    A diagram showing relation names, attributes, underlined keys, and arrows from foreign keys to the relations or keys they reference.

  39. How can dot notation resolve an ambiguous attribute name?

    Prefix the attribute with its relation name, such as course.course Id, to specify which relation's attribute is intended.

  40. What is relational algebra?

    A set of operators that take relation instances as inputs and return new relation instances.

  41. What is a database query?

    A request to retrieve specified data from a database.

  42. Why is relational algebra described as procedural?

    Its expressions specify the sequence of operations to perform on relations to obtain the desired result.

  43. What is the relationship between relational algebra expressions and trees?

    An algebraic expression can be represented as a tree in which intermediate results flow upward and the final result appears at the root.

  44. What role does relational algebra play in a relational query engine?

    It forms the core of the query engine, which uses implementations of relational algebra operators to execute queries.

  45. How does SQL relate to relational algebra?

    SQL is largely declarative, and SQL queries are internally translated into relational algebra expressions.

  46. Why can translating SQL into relational algebra enable query optimization?

    The relational algebra expression can be rewritten into an equivalent form that executes more efficiently.

  47. What are the main relational algebra operators introduced in the material?

    Selection, projection, Cartesian product, union, intersection, difference, and join.

  48. Which relational algebra operators are unary, according to the material?

    Selection and projection.

  49. What does the relational algebra selection operator do?

    It returns the tuples of a relation that satisfy a specified condition.

  50. What is the notation for selecting tuples satisfying condition θ\thetaθ from relation rrr?

    σθ(r)\sigma_\theta(r)σθ​(r).

  51. What is the schema of a selection result?

    It is the same as the schema of the input relation, including the same attributes and their order.

  52. Is selection commutative?

    Yes. Applying condition c1c_1c1​ and then c2c_2c2​ gives the same result as applying c2c_2c2​ and then c1c_1c1​.

  53. What is a basic selection condition?

    A comparison between two attributes or between an attribute and a constant of an appropriate type.

  54. What is a composite selection condition?

    A condition formed by combining basic conditions with the logical operators AND, OR, or NOT.

  55. What comparison operators can be used in selection conditions?

    Less than, less than or equal to, greater than, greater than or equal to, equal to, and not equal to.

  56. What domain requirement applies when using ordering comparisons in selection?

    The relevant attribute domains must support an ordering relationship.

  57. How would you select all professors named Giridhar?

    Apply selection to professor with the condition name = 'Giridhar': σname=′Giridhar′(professor)\sigma_{name='Giridhar'}(professor)σname=′Giridhar′​(professor).

  58. How would you select professors who joined between 1980 and 1985, inclusive?

    Select tuples satisfying 1980≤start year≤19851980 \leq start\ year \leq 19851980≤start year≤1985.

  59. What does the relational algebra projection operator do?

    It keeps only specified attributes of a relation and discards the remaining attributes.

  60. What is the notation for projecting attributes A1A_1A1​ through AkA_kAk​ from relation rrr?

    πA1,A2,…,Ak(r)\pi_{A_1, A_2, \ldots, A_k}(r)πA1​,A2​,…,Ak​​(r).

  61. What is the schema of a projection result?

    The projection list itself, containing exactly the selected attributes.

  62. Does projection preserve duplicate tuples?

    No. Relations are sets of tuples, so duplicate projected tuples are removed.

  63. Why might projection return fewer tuples than its input relation?

    Different input tuples may have identical values for the projected attributes, causing duplicates to collapse.

  64. What happens when the projection list contains the key of the input relation?

    The result has the same number of tuples as the input relation.

  65. How can projecting only name after selecting M.S. students lose information?

    Students with the same name, such as two students named Mahesh, collapse into one tuple.

  66. What does projecting roll number and name from student produce?

    A relation containing each student's roll number and name, with the same number of tuples as student.

  67. How do selection and projection differ?

    Selection chooses rows satisfying a condition; projection chooses columns to retain.

  68. What happens if a projection list does not contain the input key?

    The output may contain fewer tuples than the input, although it is not required to.

Card 1 of 68
Card 1 of 68

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent