Assignment DBDA Preeti

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 12

Database Design and Applications Assignment

Note:
1. The students in class are divided into groups, each group is assigned with 5
questions
2. Each individual in that group should answer all the 5 questions separately
3. Assignment should be hand written( no print outs) in A-4 size sheets
4. The cover page should contain Name,ID, Group No
5. The sheets need to be stapled and submitted( no files/folders)
6. Specify the question numbers properly as in the question sheet, do not start
from 1,2...
7. The last date for submission of assignment is strictly on or before: 5th Dec 2015

COURSE No. & Title: SESAP ZG518 Database Design and Applications
Assignment (Set 1)

1. What is the difference between XML schema and XML DTD?

2. Suppose we have the following requirements for a university database that is used to
keep track of students’ transcripts:
(a) The university keeps track of each student’s name (SNAME), student number
(SNUM),social security number (SSSN), current address (SCADDR) and phone
(SCPHONE),permanent address (SPADDR) and phone (SPPHONE), birthdate (BDATE),
sex (SEX),class (CLASS) (freshman, sophomore, ..., graduate), major department
(MAJORDEPTCODE),minor department (MINORDEPTCODE) (if any), and degree
program (PROG)(B.A., B.S., ..., Ph.D.). Both ssn and student number have unique
values for each student.
(b) Each department is described by a name (DEPTNAME), department code
(DEPTCODE),office number (DEPTOFFICE), office phone (DEPTPHONE), and college
(DEPTCOLLEGE). Both name and code have unique values for each department.
(c) Each course has a course name (CNAME), description (CDESC), code number
(CNUM),number of semester hours (CREDIT), level (LEVEL), and offering department
(CDEPT).The value of code number is unique for each course.
(d) Each section has an instructor (INSTUCTORNAME), semester (SEMESTER), year
(YEAR), course (SECCOURSE), and section number (SECNUM). Section numbers
distinguish different sections of the same course that are taught during the same
semester/year; its values are 1, 2, 3, ...; up to the number of sections taught during
each semester.
(e) A grade record refers to a student (Ssn), refers to a particular section, and grade
(GRADE).
Design an relational database schema for this database application. First show all the
functional dependencies that should hold among the attributes. Then, design relation
schemas for the database that are each in 3NF or BCNF. Specify the key attributes of
each relation. Note any unspecified requirements, and make appropriate assumptions
to make the specification complete.

3. Consider the LIBRARY relational database schema of Figure 4.6. Choose the
appropriate action (reject, cascade, set to null, set to default) for each referential
integrity constraint, both for the deletion of a referenced tuple, and for the update of a
primary key attribute value in a referenced tuple. Justify your choices.
4. How many serial schedules exist for the three transactions in Figure 20.8 (a)? What
are they? What is the total number of possible schedules?
5. Exercise 5.2 Consider the following schema:
Suppliers(sid: integer, sname: string, address: string)
Parts(pid: integer, pname: string, color: string)
Catalog(sid: integer, pid: integer, cost: real)
The Catalog relation lists the prices charged for parts by Suppliers. Write the following
queries in SQL:
1. Find the pnames of parts for which there is some supplier.
2. Find the snames of suppliers who supply every part.
3. Find the snames of suppliers who supply every red part.
4. Find the pnames of parts supplied by Acme Widget Suppliers and no one else.
5. Find the sids of suppliers who charge more for some part than the average cost of
that part (averaged over all the suppliers who supply that part).
6. For each part, find the sname of the supplier who charges the most for that part.
7. Find the sids of suppliers who supply only red parts.
8. Find the sids of suppliers who supply a red part and a green part.

COURSE No. & Title: : SESAP ZG518 Database Design and Applications
Assignment (Set 2)
1. What is the difference between attributes and elements in XML? List some of
the important attributes used to specify elements in XML schema.
2. Write appropriate SQL DDL statements for declaring the LIBRARY relational database
schema of Figure 4.6. Specify the keys and referential triggered actions.
3. Consider the three transactions T1, T2, and T3, and the schedules S1 and S2 given
below.Draw the serializibility (precedence) graphs for S1 and S2 and state whether
each schedule is serializable or not. If a schedule is serializable, write down the
equivalent serial schedule(s).
T1: r1(x); r1(z); w1(x)
T2: r2(z); r2(y); w2(z); w2(y)
T3: r3(x); r3(y); w3(y)
S1: r1(x); r2(z); r1(x); r3(x); r3(y); w1(x); w3(y); r2(y); w2(z); w2(y)
S2: r1(x); r2(z); r3(x); r1(z); r2(y); r3(y); w1(x); w2(z); w3(y); w2(y)

4. Suppose that the following search field values are deleted, in the given order, from the
B+tree of Exercise 17.19, show how the tree will shrink and show the final tree. The
deleted values are: 65, 75, 43, 18, 20, 92, 59, 37.

5. Consider the following relational schema. An employee can work in more than one
department; the pct time field of the Works relation shows the percentage of time that a
given employee works in a given department.
Emp(eid: integer, ename: string, age: integer, salary: real)
Works(eid: integer, did: integer, pct time: integer)
Dept(did: integer, dname: string, budget: real, managerid: integer)
Write the following queries in SQL:
1. Print the names and ages of each employee who works in both the Hardware
department and the Software department.
2. For each department with more than 20 full-time-equivalent employees (i.e., where
the part-time and full-time employees add up to at least that many full-time
employees), print the did together with the number of employees that work in
that department.
3. Print the name of each employee whose salary exceeds the budget of all of the
departments that he or she works in.
4. Find the managerids of managers who manage only departments with budgets
greater than $1 million.
5. Find the enames of managers who manage the departments with the largest budgets.
6. If a manager manages more than one department, he or she controls the sum of all
the budgets for those departments. Find the managerids of managers who control
more than $5 million.
COURSE No. & Title: : SESAP ZG518 Database Design and Applications
Assignment (Set 3)

1. What is the difference between data-centric and document-centric XML


documents?
2. Consider the universal relation R = {A, B, C, D, E, F, G, H, I} and the set of functional
dependencies F = { {A, B} -> {C}, {A} -> {D, E}, {B} -> {F}, {F} ->
{G, H}, {D} -> {I, J} }. What is the key for R? Decompose R into 2NF, then 3NF
relations.
3. Specify the following queries in SQL on the database schema of Figure 1.2.
(a) Retrieve the names of all senior students majoring in ‘COSC’ (computer science).
(b) Retrieve the names of all courses taught by professor King in 85 and 86.
(c) For each section taught by professor King, retrieve the course number, semester,
year, and number of students who took the section.
(d) Retrieve the name and transcript of each senior student (Class=5) majoring in
COSC. Transcript includes course name, course number, credit hours, semester, year,
and grade for each course completed by the student.
(e) Retrieve the names and major departments of all straight A students (students
who have a grade of A in all their courses).
(f) Retrieve the names and major departments of all students who do not have any
grade of A in any of their courses.

4 A PARTS file with Part# as key field includes records with the following Part# values:
23,65, 37, 60, 46, 92, 48, 71, 56, 59, 18, 21, 10, 74, 78, 15, 16, 20, 24, 28, 39, 43,
47, 50, 69, 75,8, 49, 33, 38. Suppose the search field values are inserted in the given
order in a B + -treeof order p=4 and p leaf =3; show how the tree will expand and
what the final tree looks like.

5 In a database, records of a relation by name EMPLOYEE are stored in a file with


following emp# (key field) values: 24, 42, 19, 30, 21, 54, 65,13,87. Now, load the
records (in same order) into expandable hashfiles based on extendible hashing.
Disk block size is 512 bytes and record size is 240 bytes. Unspanned records
organization is used. Show the structure of the directory at each step, and the local
and global depths. Use the hash function h(K)=K mod 10.

COURSE No. & Title: : SESAP ZG518 Database Design and Applications
Assignment (Set 4)

1. What are the differences between the use of tags in XML versus HTML?
2. Consider the following relations for an order-processing application database at ABC,
Inc.
ORDER (O#, Odate, Cust#, Total_amount)
ORDER-ITEM (O#, I#, Qty_ordered, Total_price, Discount%)
Assume that each item has a different discount. The Total_price refers to one item,
Odate is the date on which the order was placed, and the Total_amount is the amount
of the order. If we apply a natural join on the relations Order-Item and Order in this
database, what does the resulting relation schema look like? What will be its key?
Show the FDs in this resulting relation. Is it in 2NF? Is it in 3NF? Why or why not? (
State assumptions, if you make any )
3. Load the records with hash keys – 24, 31, 48, 65, 33, 86, 8, 51, 4, 30,16,24,70 in
the same order, into an expandable hash file using Linear hashing technique. The
family of hash functions used are- h0 (K mod 2), h1 (K mod 4), h2 (K mod 8), and so
on, where K is the hash key value.
Assume that each bucket can accommodate two records. Show the dynamic
structure of the hashing scheme after each insertion (complete working is needed)
4. Consider the instance of Sailors shown in Figure 5.1(Raghu Ramakrishna- DATABASE
MANAGEMENT SYSTEMS). Let us define instance S1 of Sailors to consist of the first
two tuples, instance S2 to be the last two tuples, and
S to be the given instance.
(a) Show the left outer join of S with itself, with the join condition being sid=sid.
(b) Show the right outer join of S with itself, with the join condition being
sid=sid.
(c) Show the full outer join of S with itself, with the join condition being sid=sid.
(d) Show the left outer join of S1 with S2, with the join condition being sid=sid.
(e) Show the right outer join of S1 with S2, with the join condition being sid=sid.
(f) Show the full outer join of S1 with S2, with the join condition being sid=sid.

5. Consider the following information about a university database:


 Professors have an SSN, a name, an age, a rank, and a research specialty.
 Projects have a project number, a sponsor name (e.g., NSF), a starting date,
an ending date, and a budget.
 Graduate students have an SSN, a name, an age, and a degree program (e.g.,
M.S.or Ph.D.).
 Each project is managed by one professor (known as the project’s principal
investigator).
 Each project is worked on by one or more professors (known as the project’s
co-investigators).
 Professors can manage and/or work on multiple projects.
 Each project is wor ked on by one or more graduate students (known as the
project’s research assistants).
 When graduate students
 work on a project, a professor must supervise their work on the project.
Graduate students can work on multiple projects, in which case they will have
a (potentially different) supervisor for each one.
 Departments have a department number, a department name, and a main
office.
 Departments have a professor (known as the chairman) who runs the
department.
 Professors work in one or more departments, and for each department that
they work in, a time percentage is associated with their job.
 Graduate students have one major department in which they are working on
their degree.
 Each graduate student has another, more senior graduate student (known as
astudent advisor) who advises him or her on what courses to take.
Design and draw an ER diagram that captures the information about the university.
Use only the basic ER model here; that is, entities, relationships, and attributes. Be
sure to indicate any key and participation constraints.

COURSE No. & Title: : SESAP ZG518 Database Design and Applications
Assignment (Set 5)

1. What are the differences between structured, semistructured, and


unstructured data?

2. Consider the following relation:


CAR_SALE(Car#, Date_sold, Salesman#, Commision%, Discount_amt
Assume that a car may be sold by multiple salesmen and hence {CAR#, SALESMAN#} is
the primary key. Additional dependencies are:
Date_sold ->Discount_amt
and
Salesman# ->commission%
a) Based on the given primary key, is this relation in 1NF, 2NF, or 3NF? Why or why not?
How would you successively normalize it completely?
b) Prove that any relation schema with two attributes is in BCNF.
3. Load the records with hash keys – 14, 61, 28, 35, 63, 46, 28, 21, 74,99,82,54,128 in the
same order, into an expandable hash file using Linear hashing technique. The family of
hash functions used are- h0 (K mod 2), h1 (K mod 4), h2 (K mod 8), and so on, where K
is the hash key value.
Assume that each bucket can accommodate two records. Show the dynamic
structure of the hashing scheme after each insertion (complete working is needed)

4. Consider the following set of requirements for a UNIVERSITY database that is used to
keep track of students’ transcripts. This is similar but not identical to the database shown
in Figure 1.2:
(a) The university keeps track of each student’s name, student number, social security
number, current address and phone, permanent address and phone, birthdate, sex, class
(freshman, sophomore, ..., graduate), major department, minor department (if any), and
degree program (B.A., B.S., ..., Ph.D.). Some user applications need to refer to the city,
state, and zip of the student’s permanent address, and to the student’s last name. Both
social security number and student number have unique values for each student.
(b) Each department is described by a name, department code, office number, office
phone, and college. Both name and code have unique values for each department.
(c) Each course has a course name, description, course number, number of semester
hours, level, and offering department. The value of course number is unique for each
course.
(d) Each section has an instructor, semester, year, course, and section number. The
section number distinguishes different sections of the same course that are taught during
the same semester/year; its values are 1, 2, 3, ..., up to the number of sections taught
during each semester.
(e) A grade report has a student, section, letter grade, and numeric grade (0, 1, 2, 3, 4 for
F, D, C, B, A, respectively).
Design an ER schema for this application, and draw an ER diagram for that schema.
Specify key attributes of each entity type and structural constraints on each relationship
type. Note any unspecified requirements, and make appropriate assumptions to make the
specification complete.
5. you were about to create an index on a relation, what considerations
would guide your choice? Discuss:
1. The choice of primary index.
2. Clustered versus unclustered indexes.
3. Hash versus tree indexes.
4. The use of a sorted file rather than a tree-based index.
5. Choice of search key for the index. What is a composite search key, and what
considerations are made in choosing composite search keys? What are index-only
plans, and what is the influence of potential index-only evaluation plans on the
choice of search key for an index?

COURSE No. & Title: : SESAP ZG518 Database Design and Applications
Assignment (Set 6 )

1. Consider the following relation for published books:


BOOK (Book_title, Authorname, Book_type, Listprice, Author_affil, Publisher)
Author_affil refers to the affiliation of the author. Suppose the following dependencies
exist:
Book_title -> Publisher, Book_type
Book_type -> Listprice
Author_name -> Author-affil
(a) What normal form is the relation in? Explain your answer.
(b) Apply normalization until you cannot decompose the relations further. State the
reasons behind each decomposition.
2. What are the current relational DBMSs that dominate the market? Choose
one that you are familiar with and show how it measures up based on the criteria
laid out in Section 10.2.3?(Chapter 10: Practical Database Design Methodology )

3. In a database, records of a relation by name EMPLOYEE are stored in a file with


following emp# (key field) values: 24, 42, 19, 30, 21, 54, 65,120,83. Now, load the
records (in same order) into expandable hashfiles based on extendible hashing. Disk
block size is 512 bytes and record size is 240 bytes. Unspanned records organization is
used. Show the structure of the directory at each step, and the local and global
depths. Use the hash function h(K)=K mod 10.
4. Try to map the relational schema in Figure 6.14(Navathe) into an ER schema. This is
part of a process known as reverse engineering, where a conceptual schema is created
for an existing implemented database. State any assumptions you make.
5. The Prescriptions-R-X chain of pharmacies has offered to give you a
free lifetime supply of medicine if you design its database. Given the rising cost of
health care, you agree. Here’s the information that you gather:
Patients are identified by an SSN, and their names, addresses, and ages must be
recorded.
Doctors are identified by an SSN. For each doctor, the name, specialty, and years
of experience must be recorded.
Each pharmaceutical company is identified by name and has a phone number.
For each drug, the trade name and formula must be recorded. Each drug is
sold by a given pharmaceutical company, and the trade name identifies a drug
uniquely from among the products of that company. If a pharmaceutical company
is deleted, you need not keep track of its products any longer.
Each pharmacy has a name, address, and phone number.
Every patient has a primary physician. Every doctor has at least one patient.
Each pharmacy sells several drugs and has a price for each. A drug could be sold
at several pharmacies, and the price could vary from one pharmacy to another.
Doctors prescribe drugs for patients. A doctor could prescribe one or more drugs
for several patients, and a patient could obtain prescriptions from several doctors.
Each prescription has a date and a quantity associated with it. You can assume
that, if a doctor prescribes the same drug for the same patient more than once,
only the last such prescription needs to be stored.
Pharmaceutical companies have long-term contracts with pharmacies. A
pharmaceutical
company can contract with several pharmacies, and a pharmacy can
contract with several pharmaceutical companies. For each contract, you have to
store a start date, an end date, and the text of the contract.
Pharmacies appoint a supervisor for each contract. There must always be a supervisor
for each contract, but the contract supervisor can change over the lifetime
of the contract.
1. Draw an ER diagram that captures the preceding information. Identify any
constraints
not captured by the ER diagram.
2. How would your design change if each drug must be sold at a fixed price by all
pharmacies?
COURSE No. & Title: : SESAP ZG518 Database Design and Applications
Assignment (Set 7)
1. What undesirable dependencies are avoided when a relation is in 2NF
and What undesirable dependencies are avoided when a relation is in 3NF?
2. A database is being constructed to keep track of the teams and games of a sports
league. A team has a number of players, not all of whom participate in each game.
It is desired to keep track of the players participating in each game for each team, the
positions they played in that game, and the result of the game. Try to design an ER
schema diagram for this application, stating any assumptions you make. Choose your
favorite sport (soccer, football, baseball ...).
3. Load the records of Exercise 16.31 into expandable hash files based on extendible
hashing. Show the structure of the directory at each step. Show the directory at each
step, and the global and local depths. Use the hash function h(k) = K mod 128.

4. Figure 9.8 shows an ER schema for a database that can be used to keep track
of transport ships and their locations for maritime authorities. Map this
schema into a relational schema and specify all primary keys and foreign
keys.
5. Consider the following relational schema. An employee can work in more than one
department; the pct time field of the Works relation shows the percentage of time that
a given employee works in a given department.
Emp(eid: integer, ename: string, age: integer, salary: real)
Works(eid: integer, did: integer, pct time: integer)
Dept(did: integer, dname: string, budget: real, managerid: integer)
Write the following queries in SQL:
1. Print the names and ages of each employee who works in both the Hardware
department and the Software department.
2. For each department with more than 20 full-time-equivalent employees (i.e., where
the part-time and full-time employees add up to at least that many full-time
employees), print the did together with the number of employees that work in
that department.
3. Print the name of each employee whose salary exceeds the budget of all of the
departments that he or she works in.
4. Find the managerids of managers who manage only departments with budgets
greater than $1 million.
5. Find the enames of managers who manage the departments with the largest
budgets.
6. If a manager manages more than one department, he or she controls the sum of all
the budgets for those departments. Find the managerids of managers who control
more than $5 million.
COURSE No. & Title: : SESAP ZG518 Database Design and Applications
Assignment (Set 8)

1. Why should NULLs in a relation be avoided as much as possible? Discuss the


problem of spurious tuples and how we may prevent it.
1b. What is a functional dependency? What are the possible sources of the information
that defines the functional dependencies that hold among the attributes
of a relation schema?
2. Consider the following set of requirements for a UNIVERSITY database that is used to
keep track of students’ transcripts. This is similar but not identical to the database
shown in Figure 1.2:
(a) The university keeps track of each student’s name, student number, social security
number, current address and phone, permanent address and phone, birthdate, sex,
class (freshman, sophomore, ..., graduate), major department, minor department (if
any), and degree program (B.A., B.S., ..., Ph.D.). Some user applications need to
refer to the city, state, and zip of the student’s permanent address, and to the
student’s last name. Both social security number and student number have unique
values for each student.
(b) Each department is described by a name, department code, office number, office
phone, and college. Both name and code have unique values for each department.
(c) Each course has a course name, description, course number, number of semester
hours, level, and offering department. The value of course number is unique for each
course.
(d) Each section has an instructor, semester, year, course, and section number. The
section number distinguishes different sections of the same course that are taught
during the same semester/year; its values are 1, 2, 3, ..., up to the number of
sections taught during each semester.
(e) A grade report has a student, section, letter grade, and numeric grade (0, 1, 2, 3,
4 for F, D, C, B, A, respectively).
Design an ER schema for this application, and draw an ER diagram for that schema.
Specify key attributes of each entity type and structural constraints on each
relationship type. Note any unspecified requirements, and make appropriate
assumptions to make the specification complete.
3. Consider the LIBRARY relational schema shown in Figure 6.14, which is used to keep
track of books, borrowers, and book loans. Referential integrity constraints are shown
as directed arcs in Figure 6.14, as in the notation of Figure 3.7. Write down relational
expressions for the following queries on the LIBRARY database:
a) How many copies of the book titled “Fundamentals of Database Systems” are
owned by the library branch “Jayanagar”, which is located in south end,
Bangalore?
b) How many copies of the book titled “Fundamentals of Data Base” are owned
by each library branch?
c) Retrieve the names of all borrowers who do not have any books checked out.
d) For each book that is loaned out from the Jayanagar branch and whose due
date is today, retrieve the book title, the borrower’s name, and the borrower’s
address.
e) For each library branch, list the number of copies of each title.
f) Retrieve the names, addresses, and number of books checked out for all
borrowers who have more than five books checked out.
g) For each book authored (or co-authored) by “Stephen King”, retrieve the title
and the number of copies owned by the library branch whose name is
“Jayanagar”.

4. a) Why is it important to use an implementation-independent data model during


conceptual schema design? What models are used in current design
tools? Why?
b) What is the difference between attributes and elements in XML? List some of
the important attributes used to specify elements in XML schema.

5. If you were about to create an index on a relation, what considerations


would guide your choice? Discuss:
1. The choice of primary index.
2. Clustered versus unclustered indexes.
3. Hash versus tree indexes.
4. The use of a sorted file rather than a tree-based index.

You might also like