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

  • 66Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Database Schema

What is a foreign key?

66 questions

  1. 1

    What is a foreign key?

    Model answer

    A foreign key is an attribute or group of attributes in one relation used to refer to tuples in another relation.

    Explanation

    Foreign keys establish references between relations in a relational database.

  2. 2

    What does the referential integrity constraint require?

    Model answer

    A foreign-key reference must refer to an existing tuple in the referenced relation, rather than being a dangling reference.

    Explanation

    This ensures that relationships between stored tuples remain valid.

  3. 3

    What does underlining an attribute in a relational schema indicate?

    Model answer

    An underlined attribute is part of a key for the relation. If multiple groups are underlined, each group represents a key.

    Explanation

    Underlining is the conventional notation for identifying keys in relational schemas.

  4. 4

    Why is roll number a key in the student relation?

    Model answer

    Roll number is a key because its value uniquely identifies each tuple or student in the student relation.

    Explanation

    No two student tuples should have the same identifying roll number.

  5. 5

    What information is stored in the student relation?

    Model answer

    The student relation stores roll number, name, degree, year of admission, sex, department number, and advisor.

    Explanation

    These attributes describe each student and connect the student to a department and advisor.

  6. 6

    What does the degree attribute represent in the student relation?

    Model answer

    It represents the academic program or degree in which the student is enrolled.

    Explanation

    Its values are strings identifying programs offered by the institute.

  7. 7

    What does the year attribute represent in the student relation?

    Model answer

    It represents the year in which the student was admitted.

    Explanation

    The year records the student’s admission year, not the current academic year.

  8. 8

    What does the advisor attribute contain, and what requirement applies to it?

    Model answer

    Advisor contains the employee ID of the faculty member advising the student, and every student is required to have an advisor.

    Explanation

    The employee ID can be used to find more information about the advisor in the professor relation.

  9. 9

    What information is stored in the department relation?

    Model answer

    The department relation stores department ID, department name, head of department, and office phone number.

    Explanation

    The head of department is the faculty member academically responsible for running the department.

  10. 10

    Why is department ID used as a key instead of the department name?

    Model answer

    Department ID is a numeric identifier that makes departments easy to identify, although the department name could also serve as a key in this example.

    Explanation

    The schema chooses a numeric ID as the designated key.

  11. 11

    What information is stored in the professor relation?

    Model answer

    The professor relation stores employee ID, name, sex, start year, department number, and phone number.

    Explanation

    Employee ID identifies the faculty member, while department number identifies the department where the professor works.

  12. 12

    What does start year represent in the professor relation?

    Model answer

    Start year is the year in which the faculty member joined the department or institute.

    Explanation

    It records when the professor began working in the relevant department.

  13. 13

    What information is stored in the course relation?

    Model answer

    The course relation stores course ID, course name, credits, and the department number of the department offering the course.

    Explanation

    Course ID uniquely identifies a course, while credits indicate the academic credit earned for completing it.

  14. 14

    What does the course ID identify?

    Model answer

    The course ID uniquely identifies a course in the course relation.

    Explanation

    It serves as the key of the course relation.

  15. 15

    What does a tuple in the enrollment relation represent?

    Model answer

    It records that a particular student enrolled in a particular course offering in a specified semester and year, along with the student’s grade.

    Explanation

    The enrollment relation captures both course registration and the resulting grade.

  16. 16

    Why does the enrollment relation require a composite key?

    Model answer

    A student may take several courses, and the same course may be offered in different semesters and years. Therefore, roll number, course ID, semester, and year are all needed to identify one enrollment.

    Explanation

    No smaller subset of these attributes is guaranteed to identify a unique course enrollment.

  17. 17

    What values can the semester attribute take in the enrollment relation?

    Model answer

    The semester attribute takes either odd or even, representing the August and January semesters, respectively.

    Explanation

    The terms odd and even are labels for the two semester periods, not descriptions of their numerical properties.

  18. 18

    When is the grade attribute null in the enrollment relation?

    Model answer

    Grade is null for a course in the current semester and receives an appropriate value after the semester ends.

    Explanation

    Completed previous semesters have recorded grades, whereas current courses may not yet have grades.

  19. 19

    What does a tuple in the teaching relation represent?

    Model answer

    It records that a professor teaches a particular course in a particular semester and year, usually with the classroom information.

    Explanation

    For example, one tuple can record an employee teaching a course during a specified offering.

  20. 20

    Why are employee ID, course ID, semester, and year all needed in the key of the teaching relation?

    Model answer

    A professor can teach several courses, a course can have several professors, and a course is offered repeatedly. The full combination identifies a specific teaching assignment.

    Explanation

    Neither a professor, course, nor course offering alone uniquely identifies a teaching tuple.

  21. 21

    What does a tuple in the prerequisite relation mean?

    Model answer

    A tuple containing prerequisite course C1 and course C2 means that C1 must be successfully completed before a student enrolls in C2.

    Explanation

    For example, a data structures course may be required before database systems.

  22. 22

    What is the purpose of the enrollment relation in the academic database?

    Model answer

    It captures which students enroll in which course offerings and the grades they receive.

    Explanation

    The relation connects students, courses, semesters, years, and grades.

  23. 23

    What is the purpose of the teaching relation in the academic database?

    Model answer

    It tracks which professors teach which courses in particular semesters and years.

    Explanation

    It represents teaching assignments from the faculty side of the database.

  24. 24

    Which attribute in the student relation is a foreign key to the department relation?

    Model answer

    Department number in the student relation is a foreign key referring to department ID in the department relation.

    Explanation

    It identifies the department in which the student is enrolled.

  25. 25

    Which attribute in the department relation refers to a professor?

    Model answer

    HOD is a foreign key referring to employee ID in the professor relation.

    Explanation

    It identifies the faculty member who heads the department.

  26. 26

    Which attributes in the prerequisite relation are foreign keys?

    Model answer

    Both prerequisite course and course ID are foreign keys referring to course ID in the course relation.

    Explanation

    Each attribute identifies a course, one as the prerequisite and the other as the dependent course.

  27. 27

    Which attribute in the teaching relation refers to the professor relation?

    Model answer

    Employee ID in the teaching relation is a foreign key referring to employee ID in the professor relation.

    Explanation

    It identifies the professor assigned to teach the course.

  28. 28

    Which attribute in the enrollment relation refers to the student relation?

    Model answer

    Roll number in the enrollment relation is a foreign key referring to roll number in the student relation.

    Explanation

    It identifies the student associated with the enrollment.

  29. 29

    Which attribute in the professor relation refers to the department relation?

    Model answer

    Department number in the professor relation is a foreign key referring to department ID in the department relation.

    Explanation

    It identifies the department in which the professor is employed.

  30. 30

    Which attribute in the course relation refers to the department relation?

    Model answer

    Department number in the course relation is a foreign key referring to department ID in the department relation.

    Explanation

    It identifies the department that offers the course.

  31. 31

    Which attributes in the enrollment relation refer to the course relation?

    Model answer

    Course ID in the enrollment relation is a foreign key referring to course ID in the course relation.

    Explanation

    It identifies the course in which the student is enrolled.

  32. 32

    Which attribute in the student relation refers to the professor relation?

    Model answer

    Advisor in the student relation is a foreign key referring to employee ID in the professor relation.

    Explanation

    It identifies the student’s faculty advisor.

  33. 33

    Must a foreign key have the same attribute name as the key it references?

    Model answer

    No. A foreign key and the referenced key may have different names, provided they represent compatible values and the foreign key refers to the correct key.

    Explanation

    For example, department number can refer to department ID.

  34. 34

    What is dot notation used for in a relational schema?

    Model answer

    Dot notation disambiguates attributes with the same name in different relations, such as course.course ID.

    Explanation

    The relation name before the dot specifies which occurrence of the attribute is intended.

  35. 35

    What information is shown in a relational schema diagram?

    Model answer

    A relational schema diagram shows relation names, attributes, underlined keys, and arrows indicating foreign-key references.

    Explanation

    The diagram provides a compact view of the database structure and its relationships.

  36. 36

    What is relational algebra?

    Model answer

    Relational algebra is a set of operators that take relation instances as inputs and return new relation instances as outputs.

    Explanation

    It is called relational algebra because its operands and results are relations.

  37. 37

    What is a database query?

    Model answer

    A query is a request to retrieve particular data from a database.

    Explanation

    Queries express what information the user wants from the stored data.

  38. 38

    Why is relational algebra described as a procedural query language?

    Model answer

    It describes the sequence of operations to perform on relations, such as selecting, combining, and projecting data.

    Explanation

    An algebraic expression specifies how to obtain the requested result.

  39. 39

    How can a relational algebra expression be viewed conceptually?

    Model answer

    It can be viewed as an expression tree in which intermediate relation results flow upward until the final result is produced at the root.

    Explanation

    Each operator consumes relation results produced by lower parts of the expression.

  40. 40

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

    Model answer

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

    Explanation

    The query engine performs the logical operations needed to produce query results.

  41. 41

    How does SQL relate to relational algebra?

    Model answer

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

    Explanation

    This translation allows the database system to reason about and execute SQL queries.

  42. 42

    Why does translating SQL into relational algebra support query optimization?

    Model answer

    The relational algebra representation allows the system to rewrite the operations into an equivalent form that may execute more efficiently.

    Explanation

    Algebraic identities can help the query engine choose a better execution strategy.

  43. 43

    Name the main relational algebra operators introduced in the content.

    Model answer

    The operators are select, project, cross product, union, intersection, difference, and join.

    Explanation

    These operators provide a powerful set of tools for expressing relational queries.

  44. 44

    Which relational algebra operators are unary, according to the content?

    Model answer

    Select and project are unary operators because each takes one relation as input.

    Explanation

    The other listed operators generally combine or compare multiple relations.

  45. 45

    How does the relational algebra select operator differ from the SQL SELECT clause?

    Model answer

    The relational algebra select operator filters tuples, whereas the SQL SELECT clause corresponds more closely to the relational algebra project operator.

    Explanation

    The similar terminology should not be confused across the two systems.

  46. 46

    What does the relational algebra select operator do?

    Model answer

    It returns all tuples in a relation that satisfy a specified condition.

    Explanation

    Selection filters rows while retaining the relation’s attributes.

  47. 47

    What is the notation for selecting tuples satisfying condition theta from relation r?

    Model answer

    The notation is sigma_\theta(r).

    Explanation

    Here, θ\thetaθ is the selection condition and rrr is the input relation.

  48. 48

    What is the schema of the result of a select operation?

    Model answer

    The result has the same schema as the input relation, including the same attributes and their order.

    Explanation

    Selection removes tuples but does not remove or rearrange columns.

  49. 49

    Why can two consecutive selection operations be reordered?

    Model answer

    Selecting tuples satisfying condition c1c_1c1​ and then condition c2c_2c2​ produces the same tuples as applying c2c_2c2​ first and then c1c_1c1​.

    Explanation

    Both orders return exactly the tuples satisfying both conditions.

  50. 50

    What is the result of applying sigma_{c_1}(sigma_{c_2}(r))?

    Model answer

    It is the set of tuples in rrr that satisfy both c1c_1c1​ and c2c_2c2​.

    Explanation

    The inner selection filters by one condition and the outer selection filters the result by the other.

  51. 51

    What forms can a basic selection condition take?

    Model answer

    A basic condition compares one attribute with another attribute or compares an attribute with a constant of an appropriate type.

    Explanation

    The attributes must belong to the relation being selected.

  52. 52

    How is a composite selection condition formed?

    Model answer

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

    Explanation

    The resulting condition is Boolean-valued.

  53. 53

    What comparison operators can be used in selection conditions?

    Model answer

    The comparison operators are less than, less than or equal to, greater than, greater than or equal to, equal to, and not equal to.

    Explanation

    They compare attribute values or an attribute value with a constant.

  54. 54

    Why must constants in a selection condition have an appropriate type?

    Model answer

    An attribute should be compared with a constant from a compatible domain, such as comparing a string with a string rather than with an integer.

    Explanation

    A comparison is meaningful only when the compared values are compatible.

  55. 55

    What selection expression retrieves all professors named Giridhar?

    Model answer

    The expression is sigma_{name = \text{'Giridhar'}}(professor).

    Explanation

    It returns every professor tuple whose name attribute equals Giridhar, including multiple tuples if several professors have that name.

  56. 56

    What selection condition retrieves professors who joined between 1980 and 1985 inclusive?

    Model answer

    Use the condition startYear≥1980startYear \geq 1980startYear≥1980 AND startYear≤1985startYear \leq 1985startYear≤1985 on the professor relation.

    Explanation

    The two inclusive comparisons ensure that professors who joined in either boundary year are included.

  57. 57

    What does the relational algebra project operator do?

    Model answer

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

    Explanation

    Projection filters columns rather than tuples.

  58. 58

    What is the notation for projecting attribute list L from relation r?

    Model answer

    The notation is pi_L(r).

    Explanation

    The list LLL contains the attributes to retain from relation rrr.

  59. 59

    What restrictions apply to the attributes in a projection list?

    Model answer

    Every attribute in the projection list must belong to the schema of the input relation, and the attributes need not be consecutive.

    Explanation

    Projection can select any desired subset of the input relation’s attributes.

  60. 60

    What is the schema of the result of a projection?

    Model answer

    The result schema consists exactly of the attributes listed in the projection list, in the specified order.

    Explanation

    All attributes not listed are removed from the result.

  61. 61

    Why can projection produce fewer tuples than its input relation?

    Model answer

    Different input tuples may have identical values for the projected attributes, and duplicate tuples are removed because a relation is a set.

    Explanation

    Projection retains only distinct combinations of the selected attribute values.

  62. 62

    What information is lost when only name is projected from the student relation?

    Model answer

    All attributes other than name are discarded, and students with the same name become represented by one tuple.

    Explanation

    For example, two students named Mahesh cannot be distinguished after projecting only name.

  63. 63

    What is the result of projecting roll number and name from the student relation?

    Model answer

    The result contains the roll number and name of every student and has the same number of tuples as the student relation.

    Explanation

    Because roll number is a key, no two students can produce the same projected combination.

  64. 64

    How does including a key in a projection list affect the number of result tuples?

    Model answer

    If the projection list contains a key of the input relation, the result has the same number of tuples as the input.

    Explanation

    A key makes every projected tuple distinct.

  65. 65

    What happens to the number of tuples when the projection list does not contain a key?

    Model answer

    The result can contain fewer tuples than the input because distinct input tuples may collapse into the same projected tuple.

    Explanation

    The number may decrease, although it cannot increase.

  66. 66

    How can a result relation be given a name in relational algebra?

    Model answer

    A relation expression can be assigned to a new relation name, such as defining r1=πL(r2)r_1 = \pi_L(r_2)r1​=πL​(r2​).

    Explanation

    Naming an intermediate result allows it to be used later in another operation.

1 of 66
Question 1 of 66

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent