Dbms Regular Test 1 Key
Dbms Regular Test 1 Key
Every column that has a compound course number (a department abbreviation and the actual
number part) should be split into two columns, one for the course department and one for the
actual course number. So: in table SECTION, Course_number → Course_dept and
Course_num; in table PREREQUISITE, Course_number → Course_dept and Course_num,
Prerequisite_number → Prereq_dept and Prereq_num; and in
table COURSE, Course_number → Course_dept and Course_num. (In this last case, there's
already a Department column that looks like it has the same information
as Course_dept would, so that column may not be needed. It depends on whether they both
use the same abbreviations.)
Explanation [2.5M]
Rewriting the tables with new columns [2M]
Q.2. Describe the structure of a DBMS. If your operating system is upgraded to support
some new functions on as files (e.g., the ability to force some sequence of bytes to disk),
which layer(s) of the DBMS would you have to rewrite to take advantage of these new
functions?
[4.5 M]
Explanation [2.5M]
Diagram [2M]
Q.3. Give some additional views that may be needed by other user groups for the
Database [8 M]
Answer:
Key
There may be more possible view which can be created for different constraints. Some of the
possible constraints are as follows,
(a) The StudentNumber should be unique for each STUDENT record (key constraint).
(b) The CourseNumber should be unique for each COURSE record (key constraint).
(c) A value of CourseNumber in a SECTION record must also exist in some COURSE record
(referential integrity constraint).
(d) A value of StudentNumber in a GRADE_REPORT record must also exist in some
STUDENT record (referential integrity constraint).
(e) The value of Grade in a GRADE_REPORT record must be one of the values in the set
{A, B, C, D, F, I, U, S} (domain constraint).
(f) Every record in COURSE must have a value for CourseNumber (entity integrity
constraint).
(g) A STUDENT record cannot have a value of Class=2 (sophomore) unless the student has
completed a number of sections whose total course CreditHours is greater than 24 credits
(general semantic integrity constraint).
Q.4. Although you always wanted to be an artist, you ended up being an expert on
databases because you love to cook data and you somehow confused database with data
baste. Your old passion is still there, however, so you set up a database company,
ArtBase, that builds a product for art galleries. The core of this product is a database
with a schema that captures all the information that galleries need to maintain.
Galleries keep information about artists, their names (which are unique), birthplaces,
age, and style of art. For each piece of artwork, the artist, the year it was made, its
unique title, its type of art (e.g., painting, lithograph, sculpture, photograph), and its
price must be stored. Pieces of artwork are also classified intogroups of various kinds,
for example, portraits, still lifes, works by Picasso, or works of the 19th century; a given
piece may belong to more than one group. Each group is identified by a name (like those
just given) that describes the group. Finally, galleries keep information about
customers. For each customer, galleries keep that person's unique name, address, total
amount of dollars spent in the gallery (very important!), and the artists and groups of
art that the customer tends to like.Draw the ER diagram for the database.[8M]
Diagram [4M]
Constraints [4M]
Diagram [6M]
Constraints [6.5M]
Q.6. Design Relational Model for the below mentioned ER diagram
COLLEGE(CName, COffice, CPhone)
DEPT (DName, Dcode, Doffice, DPhone)
COURSE(CCode, Credits, CoName, Level, CDesc)
INSTRUCTOR (Id, Rank, IName, IOffice, IPhone)
STUDENT (Sid, DOB, SName)
SECTION (SecId, SecNo, Sem, Year, Croom, DaysTime)
Tables [6M]
Insert records according to mentioned constraints [6.5M]
Q.7. Consider the following relations for a database that keeps track of student
enrollment in courses and the books adopted for each course:
STUDENT(Ssn, Name, Major, Bdate)
COURSE(Course#, Cname, Dept)
ENROLL(Ssn, Course#, Quarter, Grade)
BOOK_ADOPTION(Course#, Quarter, Book_isbn)
TEXT(Book_isbn, Book_title, Publisher, Author). Specify the foreign keys for this
schema, stating any assumptions you make.
Q.8. Database design often involves decisions about the storage of attributes. For
example, a Social Security number can be stored as one attribute or split into three
attributes (one for each of the three hyphen-delineated groups of numbers in a Social
Security number—XXX-XX-XXXX). However, Social Security numbers are usually
represented as just one attribute. The decision is based on how the database will be
used. This exercise asks you to thinkabout specific situations where dividing the SSN is
useful. [4.5 M]
a. However, Social Security Number is usually stored in one attribute. The decision is usually
based on how the database will be used. This exercise asks you to think about specific
situations where dividing the SSN is useful.perhaps the country code (for dialing
international phone numbers).
b. It is recommended to store the numbers in separate attributes since they have their own
independent existence and makes it easier to make any change.
c. For example, if an area code region were split into two regions and we have the area code
in a separate attribute; it will be easier to update it.
d. It only makes sense to split the SSN into its component if we are going to use the
subsequences to make deductions about validity, geography, etc.
Q.9. Suppose that each of the following Update operations is applied directly to the
database state shown in the above figure. Discuss all integrity constraints violated by
each operation, if any, and the different ways of enforcing these constraints.
i. Insert into PROJECT.
ii. Delete the EMPLOYEE tuple with Ssn = ‘987654321’
iii. Modify the Super_ssn attribute of the EMPLOYEE tuple with Ssn = ‘999887777’ to
‘943775543’
i) No constrain violated here.
ii) Delete the EMPLOYEE tuple with SSN= '987654321’. Violates referential integrity
because several tuples exist in the WORKS_ON, DEPENDENT,DEPARTMENT, and
EMPLOYEE relations that reference the tuple being deleted fromEMPLOYEE. We may
enforce the constraint by: (i) rejecting the deletion, or (ii) deleting all tuplesin the
WORKS_ON, DEPENDENT, DEPARTMENT, and EMPLOYEE relations whose values
forESSN, ESSN, MGRSSN, and SUPERSSN, respectively, is equalto'987654321'.
iii) Modify theSUPERSSN attribute of theEMPLOYEE tuple
withSSN='999887777'to'943775543'.Violates referential integrity because the new value
ofSUPERSSN='943775543' andthereis no tuple in the EMPLOYEE relationwith
SSN='943775543'. We may enforcetheconstraintby: (i) rejecting the deletion, or (ii)
inserting a new EMPLOYEE tuplewithSSN='943775543'.
iInsert [2M]
ii. Delete [2M[
iii. Modify [4M]
Q.10. Recent changes in privacy laws have disallowed organizations from using Social
Security numbers to identify individuals unless certain restrictionare satisfied. As a
result, most U.S. universities cannot use SSNs as primary keys (except for financial
data). In practice, Student_id, a unique identifier assigned to every student, is likely to
be used as the primary key rather than SSN since Student_id can be used throughout
the system.a. Some database designers are reluctant to use generated keys (also known
surrogate keys) for primary keys (such as Student_id) because they are artificial. Can
you propose any natural choices of keys that can be used to identify the student record
in a UNIVERSITY database?b. Suppose that you are able to guarantee uniqueness of a
natural key that includes last name. Are you guaranteed that the last name will not
change during the lifetime of the database? If last name can change, what solutions can
you propose for creating a primary key that still includes last name but remains
unique?c. What are the advantages and disadvantages of using generated (surrogate)
keys?
a. By keeping the name attributes separated, we allow the possibility of looking these pieces
of their name. In a practical use, it is not likely that the user will know the correct primary
key for a given student and so we must consider how a user will locate the correct row
without this information. If we were to collapse the name into a single attribute, then we have
complicated any sort of “lookup by name” query; such a query would then require partial
string matching and any results might not disambiguate between FirstName and LastName.
Therefore, a practical system should allow name searches by FirstName and LastName; we
must leave MiddleInitial separated still to avoid ambiguities from combining these pieces
together.
b. A single attribute Phone # would no longer suffice if a student were able to have multiple
phone numbers. We could possibly have multiple rows for a single student to allow this to
happen, but then we have violated key principles of database design (e.g. having redundant
data). A better solution would be to include the additional attributes HomePhone, CellPhone,
and OfficePhone and allow the possibility of these attributes to have no value. Again, this is
not most desirable because most students will not have all three of these attributes, and we
will have many valueless key/attribute pairs. An excellent solution would be add an
additional relation Phone# (SSN, Type, Number) while removing PhoneNumber from the
Student relationship. This new relationship would allow the one-to-many relationship from
students to phone numbers without creating redundant data or wasting space on sparse,
valueless attributes.
C.
Advantages of using generated (surrogate) keys
➢ Surrogate keys are unique.
➢ Surrogate keys apply uniform rules to all records.
➢ Surrogate keys stand the test of time.
➢ Surrogate keys allow for unlimited values.
Disadvantages of using generated (surrogate) keys
➢ Natural keys do not apply uniform rules for each record.
➢ Natural keys do not stand the test of time.
➢ Natural keys can be easily confused with each other.
a. [2M]
b. [2M[
c. [4M]
Q.11. Specify the following queries in SQL on the database schema of below mentioned
figure
a. Retrieve the names of all senior students majoring in ‘cs’ (computer science).
b. Retrieve the names of all courses taught by Professor King in 2007 and 2008.
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 = 4) majoring in CS. A
transcript includes course name, course number, credit hours, semester, year, and
grade for each course completed by the student.
a) SELECT Name FROM STUDENT WHERE Major='CS'
b)SELECT CourseName FROM COURSE, SECTION WHERE
COURSE.CourseNumber=SECTION.CourseNumber AND Instructor='King' AND
(Year='85' OR Year='86') Another possible SQL query uses nesting as follows: SELECT
CourseName FROM COURSE WHERE CourseNumber IN ( SELECT CourseNumber
FROM SECTION WHERE Instructor='King' AND (Year='85' OR Year='86') );
c) SELECT CourseNumber, Semester, Year, COUNT(*)FROM SECTION,
GRADE_REPORT
WHERE Instructor='King' AND
SECTION.SectionIdentifier=GRADE_REPORT.SectionIdentifier
GROUP BY CourseNumber, Semester, Year;
d) SELECT Name, CourseName, C.CourseNumber, CreditHours, Semester, Year, Grade
FROM STUDENT ST, COURSE C, SECTION S, GRADE_REPORT G
WHERE Class=5 AND Major='COSC' AND ST.StudentNumber=G.StudentNumber AND
G.SectionIdentifier=S.SectionIdentifier AND S.CourseNumber=C.CourseNumber;
a. Retrieve the names of all senior students majoring in ‘cs’ (computer science). [3M]
b. Retrieve the names of all courses taught by Professor King in 2007 and 2008. [3M]
c. For each section taught by Professor King, retrieve the course number, semester,
year, and number of students who took the section. [3M]
d. Retrieve the name and transcript of each senior student (Class = 4) majoring in CS. A
transcript includes course name, course number, credit hours, semester, year, and
grade for each course completed by the student. [3.5M]
Q.12. Consider the following relational schema and briefly answer the questions that
follow: Emp(eid: integer, cname: string, age: integer, salary: real) \Vorks( eid: integer,
did: integer, pet-time: integer) Dept( did.' integer, budget: re~l, managerid: integer)
1. Define a table constraint on Emp that will ensure that every employee makes at least
$10,000.
2. Define a table constraint on Dept that will ensure that all managers have age> 30;
3. Define an assertion on Dept that will ensure that all managers have age> 30.Compare
this assertion with the equivalent table constraint. Explain which is better.
4. Write SQL statements to delete all information about employees whose salaries
exceed that of the manager of one or more departments that they work in. Be sure to
ensure that all the relevant integrity constraints are satisfied after your updates.
1. CREATE TABLE Emp (eid INTEGER, ename CHAR(10), age INTEGER, salary
REAL, PRIMARY KEY (eid), CHECK (salary >= 10000) )
2. CREATE TABLE Dept (did INTEGER, buget REAL, managerid INTEGER,
PRIMARY KEY (did), FOREIGN KEY (managerid) REFERENCES Emp,
CHECK((SELECT E.age FROM Emp E, Dept D) WHERE E.eid=D.managerid)>30);
3.
option1.
CREATE TABLE Dept (did INTEGER, budget REAL, managerid INTEGER,
PRIMARY KEY (did))The condition is checked only when the Dept relation
is being updated;
option2.
CREATE ASSERTION managerAge CHECK ((SELECT E.age FROM Emp
E, Dept D WHERE E.eid = D.managerid )> 30 ). It checks for potential
violation of the assertion whenever one of the relations is updated
4. To write such statements, it is necessary to consider the constraints defined over the
tables. We will assume the following: CREATE TABLE Emp ( eid INTEGER, ename
CHAR(10), age INTEGER, salary REAL, PRIMARY KEY (eid) ) CREATE TABLE
Works (eid INTEGER, did INTEGER, pcttime INTEGER, PRIMARY KEY(eid, did),
FOREIGN KEY(did) REFERENCES Dept, FOREIGN KEY(eid) REFERENCES
Emp, ON DELETE CASCADE) CREATE TABLE Dept ( did INTEGER, buget
REAL, managerid INTEGER, PRIMARY KEY(did), FOREIGN KEY(managerid)
REFERENCES Emp, ON DELETE SET NULL);
1. Retrieve the names of all senior students majoring in ‘cs’ (computer science). [3M]
2. Retrieve the names of all courses taught by Professor King in 2007 and 2008. [3M]
3. For each section taught by Professor King, retrieve the course number, semester, year,
and number of students who took the section. [3M]
4. Retrieve the name and transcript of each senior student (Class = 4) majoring in CS. A
transcript includes course name, course number, credit hours, semester, year, and grade
for each course completed by the student. [3.5M]