Foreign Keys and Referential Integrity
- 68Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- ←Previous card
- →Next card
What is a foreign key?
A group of attributes in one relation used to refer to tuples in another relation.
Or swipe the card
68 cards
What is a foreign key?
A group of attributes in one relation used to refer to tuples in another relation.
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.
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.
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 numberanddepartment Id.Which attribute in
studentrefers to the department relation?department numberis a foreign key referring to the department identifier.Which attribute in
studentidentifies the student's advisor?advisoris a foreign key referring to the employee ID of a professor.Which attribute in
departmentidentifies its head of department?hodis a foreign key referring to the employee ID of a professor.Which attributes in
prerequisitereference the course relation?Both
preReqCourseandcourse Idare foreign keys referring to the course ID.Which attributes in
enrollmentare foreign keys?roll numberrefers tostudent, andcourse Idrefers tocourse.Which attributes in
professor,course, andteachingreference other relations?Professor's
department numberrefers todepartment; course'sdepartment numberrefers todepartment; teaching'semployee Idandcourse Idrefer toprofessorandcourse, respectively.What does underlining an attribute or group of attributes in a relational schema indicate?
It indicates that the attribute or group is a key.
What is the key of the
studentrelation, and why?roll number; its value uniquely identifies each student tuple.What does a key guarantee about tuples in a relation?
No two tuples have the same value for the key.
What attributes belong to the
studentrelation?roll number,name,degree,years,sex,department number, andadvisor.What does the
degreeattribute instudentrepresent?The academic program in which the student is enrolled.
What does the
yearsattribute instudentrepresent?The student's year of admission.
What information is stored in the
departmentrelation?department Id,name,hod, andphone.Why is
department Idused 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.
What does
hodrepresent in thedepartmentrelation?The faculty member who heads and is academically responsible for running the department.
What attributes belong to the
professorrelation?employee Id,name,sex,start year,department number, andphone number.What does
start yearmean in theprofessorrelation?The year in which the faculty member joined the department.
What attributes belong to the
courserelation?course Id,c name,credits, anddepartment number.What does
c namerepresent in thecourserelation?The name of the course.
What does the
creditsattribute represent?The number of credits earned by successfully completing the course.
What is the key of the
courserelation?course Id.What does the
enrollmentrelation record?Which students enroll in which courses, in which semester and year, and the grade they receive.
What is the key of the
enrollmentrelation?The combination of
roll number,course Id,semester, andyear.Why is
course Idalone insufficient as the key ofenrollment?A course is offered multiple times and can have many enrolled students.
Why are
semesterandyearpart of the enrollment key?They identify the particular offering of a course in which the student enrolled.
What values can
semestertake in the enrollment relation?oddoreven, representing the August and January semesters, respectively.What value does
gradehave during the current semester?Null.
What does the
teachingrelation record?Which professor teaches which course in a particular semester and year, including the classroom.
What is the key of the
teachingrelation?The combination of
employee Id,course Id,semester, andyear.Why is
employee Idalone not a key ofteaching?A professor may teach several courses over the course of employment.
Why is
course Idalone not a key ofteaching?A course may be taught by several professors and offered in different semesters and years.
What does a tuple (C1,C2) in
prerequisitemean?C1 must be successfully completed before a student enrolls in C2.
Give an example of a prerequisite relationship from the schema.
Data Structures may be a prerequisite for Database Systems.
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.
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.What is relational algebra?
A set of operators that take relation instances as inputs and return new relation instances.
What is a database query?
A request to retrieve specified data from a database.
Why is relational algebra described as procedural?
Its expressions specify the sequence of operations to perform on relations to obtain the desired result.
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.
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.
How does SQL relate to relational algebra?
SQL is largely declarative, and SQL queries are internally translated into relational algebra expressions.
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.
What are the main relational algebra operators introduced in the material?
Selection, projection, Cartesian product, union, intersection, difference, and join.
Which relational algebra operators are unary, according to the material?
Selection and projection.
What does the relational algebra selection operator do?
It returns the tuples of a relation that satisfy a specified condition.
What is the notation for selecting tuples satisfying condition θ from relation r?
σθ(r).
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.
Is selection commutative?
Yes. Applying condition c1 and then c2 gives the same result as applying c2 and then c1.
What is a basic selection condition?
A comparison between two attributes or between an attribute and a constant of an appropriate type.
What is a composite selection condition?
A condition formed by combining basic conditions with the logical operators AND, OR, or NOT.
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.
What domain requirement applies when using ordering comparisons in selection?
The relevant attribute domains must support an ordering relationship.
How would you select all professors named Giridhar?
Apply selection to
professorwith the conditionname = 'Giridhar': σname=′Giridhar′(professor).How would you select professors who joined between 1980 and 1985, inclusive?
Select tuples satisfying 1980≤start year≤1985.
What does the relational algebra projection operator do?
It keeps only specified attributes of a relation and discards the remaining attributes.
What is the notation for projecting attributes A1 through Ak from relation r?
πA1,A2,…,Ak(r).
What is the schema of a projection result?
The projection list itself, containing exactly the selected attributes.
Does projection preserve duplicate tuples?
No. Relations are sets of tuples, so duplicate projected tuples are removed.
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.
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.
How can projecting only
nameafter selecting M.S. students lose information?Students with the same name, such as two students named Mahesh, collapse into one tuple.
What does projecting
roll numberandnamefromstudentproduce?A relation containing each student's roll number and name, with the same number of tuples as
student.How do selection and projection differ?
Selection chooses rows satisfying a condition; projection chooses columns to retain.
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.

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