You are on page 1of 8

Introduction to the Relational Model

Question 1 : Define - Super Keys,Candidate Keys,Primary Keys with example.


Answer :
Super Keys : A super key is a combination of columns that uniquely identifies
any row within a relational database management system (RDBMS) table.A
candidate key is a closely related concept where the super key is reduced to the
minimum number of columns required to uniquely identify each row.
Candidate Keys : A candidate key is a column or set of columns in a table that
can uniquely identify any database record without referring to any other
data.Each table may have one or more candidate keys but one candidate key is
unique and it is called the primary key.
Primary Key : A primary key,also called a primary keyword is a key in a
relational database that is unique for each record.It is a unique identifier such as
a driver license number,telephone number (including area code) or vehicle
identification number (VIN),A relational Database must always have one and
only primary key.
Lets take an example to understand super keys,candidate keys and primary key.
Emp_SSN Emp_Number Emp_Name
123456789 226 Jayed
999999321 227 Lipi
888997212 228 Asik
777778888 229 Helal

Super Keys :
 {Emp_SSN}
 {Emp_Number}
 {Emp_SSN,Emp_Number}
 {Emp_SSN,Emp_Number,Emp_Name}
 {Emp_Number,Emp_Name}
All of this above sets are able to uniquely identified.
Candidate key : As stated above that they are the minimal super keys with no
redundant attributes.

1
 {Emp_SSN}
 {Emp_Number}
Only these two sets are candidate keys as another sets are having redundant
attributes these are not necessary for unique identification.
Primary Key : Primary key is being selected from the sets of candidate keys by
database designer.So either {Emp_SSN} or {Emp_Number} can be the primary
key.
Question 2 : Write down any five symbols with examples of relational algebra.
Answer :

Symbol (Name) Example of Use

σ σ
salary > = 85000 (instructor)
(Selection) Return rows of the input relation that satisfy the
predicate.

Π ΠID, salary (instructor)


(Projection) Output specified attributes from all rows of the
input relation. Remove duplicate tuples from the
output
x instructor x department
(Cartesian Product) Output pairs of rows from the two input relations
that have the same value on all attributes that have
the same name
Π name (instructor) ∪ Π name (student)

(Union) Output the union of tuples from the two input
relations.

⋈ instructor ⋈ department
(Natural Join) Output pairs of rows from the two input relations
that have the same value on all attributes that have
the same name.

2
Solution Of Practice Exercises

Question 2.1 : Consider the relational database of Figure 2.14 What are the
appropriate primary keys?
Answer : The answer is shown in Figure 2.1, with primary keys underlined.
Question 2.2 : Consider the foreign key constraint from the dept_name attribute
of instructor to the department relation.Give examples of inserts and deletes to
these relations,which can cause a violation of the foreign key constraint.
Answer : Inserting a tuple :
(10111, Ostrom, Economics, 110,000)
Into the instructor table,where the department table does not have the department
Economics, would violate the foreign key constraint.
Deleting the tuple :
(Biology, Watson, 90000)
from the department table, where at least one student or instructor tuple has dept
name as biology, would violate the foreign key constraint.
employee (person_name, street, city)
works (person_name, company_name, salary)
company (company_name, city)
Figure 2.1 : Relational database for Practice Exercise 2.1.
Question 2.3 : Consider the time_slot relation. Given that a particular time slot
can meet more than once in a week, explain why day and start_time are part of
the primary key of this relation, while end_time is not.
Answer : The attributes day and start_time are part of the primary key since a
particular class will most likely meet on several different days, and may even
meet more than once in a day. However, end_time is not part of the primary key
since a particular class that starts at a particular time on a particular day cannot
end at more than one time.
Question 2.4 : In the instance of instructor shown in Figure??.. no two instructors
have the same name. From this, can we conclude that name can be used as a
superkey (or primary key) of instructor?

3
Answer : No. For this possible instance of the instructor table the names are
unique, but in general this may not be always the case (unless the university has
a rule that two instructors cannot have the same name, which is a rather unlikey
scenario).
Question 2.5 : What is the result of first performing the cross product of student
and advisor, and then performing a selection operation on the result with the
predicate s_id = ID? (Using the symbolic notation of relational algebra, this query
can be written as σs_id = ID(student × advisor).)
Answer : The result attributes include all attribute values of student followed by
all attributes of advisor. The tuples in the result are as follows. For each student
who has an advisor, the result has a row containing that students
attributes,followed by an s_id attribute identical to the students ID attribute,
followed by the i_id attribute containing the ID of the students advisor.
Students who do not have an advisor will not appear in the result. A student who
has more than one advisor will appear a corresponding number of times in the
result.
Question 2.6 : Consider the following expressions, which use the result of a
relational algebra operation as the input to another operation.For each expression,
explain in words what the expression does.
a. σyear ≥ 2009(takes) |×| student
b. σyear ≥ 2009(takes |×| student)
c. ΠID,name,course_id(student |×| takes)
Answer :
a. For each student who takes at least one course in 2009, display the students
information along with the information about what courses the student took.
The attributes in the result are:
ID, name, dept_name, tot_cred, course_id, section_id, semester, year, grade
b. Same as (a); selection can be done before the join operation.
c. Provide a list of consisting of
ID, name, course_id
of all students who took any course in the university.
Question 2.7 : Consider the relational database of Figure 2.14 Give an expression
in the relational algebra to express each of the following queries :

4
a. Find the names of all employees who live in city “Miami”.
b. Find the names of all employees whose salary is greater than $100,000.
c. Find the names of all employees who live in “Miami” and whose salary is
greater than $100,000.

Answer :
a. Πname (σcity = “Miami” (employee))
b. Πname (σsalary >100000 (employee))
c. Πname (σcity = “Miami” ∧ salary>100000 (employee))
Question 2.8 : Consider the bank database of Figure 2.15 Give an expression in
the relational algebra for each of the following queries.
a. Find the names of all branches located in “Chicago”.
b. Find the names of all borrowers who have a loan in branch “Downtown”.
Answer:
a. Πbranch_name (σbranch_city = “Chicago” (branch))
b. Πcustomer_name (σbranch_name = “Downtown” (borrower |× loan))

5
Solution Of Exercises

Question 2.9 : Consider the bank database of Figure 2.15.


a. What are the appropriate primary keys?
b. Given your choice of primary keys,identify appropriate foreign keys.
Answer :
a. employee (person_name, street, city)
works (person_name, company_name, salary)
company (company_name, city)
Figure 2.14 : Relational database for Exercises 2.1, 2.7, and 2.12.
branch(branch_name, branch_city, assets)
customer (customer_name, customer_street, customer_city)
loan (loan_number, branch_name, amount)
borrower (customer_name, loan_number)
account (account_number, branch_name, balance)
depositor (customer_name, account_number)
Figure 2.15 : Banking database for Exercises 2.8, 2.9, and 2.13.
b. 1. The primary keys of the various schema are underlined. Although in a real
bank the customer name is unlikely to be a primary key, since two customers
could have the same name, we use a simplified schema where we assume that
names are unique.We allow customers to have more than one account, and more
than one loan.
branch(branch_name, branch_city, assets)
customer (customer_name, customer_street, customer_city)
loan (loan_number, branch_name, amount)
borrower (customer_name, loan_number)
account (account_number, branch_name, balance)
depositor (customer_name, account_number)

6
2. The foreign keys are as follows :
i. For loan : branch_name referencing branch.
ii. For borrower : Attribute customer_name referencing customer and
loan_number referencing loan
iii. For account : branch_name referencing branch.
iv. For depositor : Attribute customer_name referencing customer and
account_number referencing account
Question 2.10 : Consider the advisor relation shown in Figure 2.8, with s_id as
the primary key of advisor. Suppose a student can have more than one advisor.
Then, would s id still be a primary key of the advisor relation? If not, what should
the primary key of advisor be?
Answer : No, s_id would not be a primary key, since there may be two (or more)
tuples for a single student, corresponding to two (or more) advisors. The primary
key should then be s_id, i_id.
Question 2.11 : Describe the differences in meaning between the terms relation
and relation schema.
Answer : A relation schema is a type definition,and a relation is an instance of
that schema. For example, student (ss#, name) is a relation schema and
123-456-222 John
234-567-999 Mary
is a relation based on that schema.
Question 2.12 : Consider the relational database of Figure 2.14. Give an
expression in the relational algebra to express each of the following queries :
a. Find the names of all employees who work for “First Bank Corporation”.
b. Find the names and cities of residence of all employees who work for “First
Bank Corporation”.
c. Find the names,street address,and cities of residence of all employees who
work for “First Bank Corporation” and earn more than $10,000.
Answer :
a. Πperson_name (σcompany_name = “First Bank Corporation” (works))
b. Πperson_name,city (employee |×| (σcompany_name = “First Bank Corporation” (works)))

7
c. Πperson_name, street, city (σcompany_name = “First Bank Corporation” ∧ salary > 10000)
(works |×| employee))
Question 2.13 : Consider the bank database of Figure 2.15. Give an expression
in the relational algebra for each of the following queries:
a. Find all loan numbers with a loan value greater than $10,000.
b. Find the names of all depositors who have an account with a value greater than
$6,000.
c. Find the names of all depositors who have an account with a value greater than
$6,000 at the “Uptown” branch.
Answer:
a. Πloan_number (σamount > 10000(loan) )
b. Πcustomer_name (σbalance> 6000 (depositor |×| account))
c. Πcustomer_name (σbalance> 6000∧branch_name=“Uptown” (depositor |×| account))
Question 2.14 : List two reasons why null values might be introduced into the
database.
Answer : Nulls may be introduced into the database because the actual value is
either unknown or does not exist.For example,an employee whose address has
changed and whose new address is not yet known should be retained with a null
address. If employee tupleshave a composite attribute dependents, and a
particular employee has no dependents, then that tuple’s dependents attribute
should be given a null value.
Question 2.15 : Discuss the relative merits of procedural and nonprocedural
languages.
Answer : Nonprocedural languages greatly simplify the specification of queries
(at least, the types of queries they are designed to handle). The free the user from
having to worry about how the query is to be evaluated; not only does this reduce
programming effort, but in fact in most situations the query optimizer can do a
much better task of choosing the best way to evaluate a query than a programmer
working by trial and error. On the other hand, procedural languages are far more
powerful in terms of what computations they can perform. Some tasks can either
not be done using nonprocedural languages, or are very hard to express using
nonprocedural languages, or execute very inefficiently if specified in a
nonprocedural manner.

You might also like