0% found this document useful (0 votes)
11 views

Assignment DBMS

DATABASE MANAGEMENT SYSTEM

Uploaded by

sahilmutreja100
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Assignment DBMS

DATABASE MANAGEMENT SYSTEM

Uploaded by

sahilmutreja100
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 48

Pa g e |

1
Pa g e | 2

ASSIGNMENT 1
CHAPTER 1
Q1. Define the following terms:
a) Database catalog and meta-data,
b) Program-data independence,
c) DBA
d) Canned transactions,
e) Deductive database system,
f) Persistent object,
g) Transaction-processing application.

A1. a) The database catalog of a database instance consists


of metadata in which definitions of database objects such
as base tables, views (virtual tables), synonyms, value
ranges, indexes, users, and user groups are stored.
Metadata is simply data about data. It means it is a
description and context of the data. It helps to organize,
find and understand data.
Pa g e | 3

b)Program-Data independence is the ability of to make


changes to data characteristics without have to make
changes to the programs that access the data. Program-data
independence also refers to the capability of
leaving data intact and accessible regardless of
modifications to the database that contains the data.

c)A DBA (Database Administrator) is the information


technician who makes sure an organization's database and
its related applications operate functionally and efficiently.

d)Canned transactions are standard types of queries and


updates which are frequently used by Naive end users to
constantly querying and updating database. These are
the transactions that are carefully programmed and tested.

e)A deductive database is a database system that can


make deductions based on rules and facts stored in the
deductive database. Deductive databases are more
expressive than relational databases but less expressive than
logic programming systems.
Pa g e | 4

f)A persistent object is an object that has been assigned a


storage location in a federated database. When you commit
the transaction in which you create a persistent object, that
object's data is saved in the database; the object can then
be accessed by other processes.

g)Transaction processing means dividing information


processing up into individual, indivisible operations, called
transactions, that complete or fail as a whole; a
transaction can't remain in an intermediate, incomplete,
state.

Q2. Differentiate between Database management system


and Traditional file system.

A2.
Pa g e | 5

Database Management Traditional File Systems


Systems

Database Management File system is basically a


System is basically a way of arranging the files in
software that manages the a storage medium like hard
collection of related data. disk.

It is used for storing data and File system organizes the


retrieving the data files and helps in retrieval of
effectively when it is needed. files when they are
required.

In Database Management File system performs basic


System the data can be operations like management,
fetched by SQL queries and file naming, giving access
relational algebra. rules etc.

Q3. What are the responsibilities of the DBA? Explain


in detail.
Pa g e | 6

A3. Responsibilities of a database administrator are :-


Allocating system storage and planning storage
requirements for the database system

Modifying the database structure, as necessary, from
information given by application developers

Enrolling users and maintaining system security

Ensuring compliance with database vendor
license agreement

Controlling and monitoring user access to the
database

Monitoring and optimizing the performance of the
database

Planning for backup and recovery of database
information

Maintaining archived data

Q4. Briefly explain the main activities different types of


database end users perform.

A4. Categories of End users & activities performed:-


Pa g e | 7

i. Casual End Users

These are the users who occasionally access the database


but they require different information each time. They use a
sophisticated database query language basically to specify
their request and are typically middle or level managers or
other occasional browsers. These users learn very few
facilities that they may use repeatedly from the multiple
facilities provided by DBMS to access it.

ii. Naive or parametric end users

These are the users who basically make up a sizeable


portion of database end users. The main job function
revolves basically around constantly querying and updating
the database for this we basically use a standard type of
query known as canned transaction that have been
programmed and tested. These users need to learn very
little about the facilities provided by the DBMS they
basically have to understand the users interfaces of the
standard transaction designed and implemented for their
use.
iii. Sophisticated end users

These users basically include engineers, scientist, business


analytics and others who thoroughly familiarize themselves
with the facilities of the DBMS in order to implement their
application to meet their complex requirement. These
users
Pa g e | 8

try to learn most of the DBMS facilities in order to achieve


their complex requirements.

iv. Standalone users

These are those users whose job is basically to maintain


personal databases by using a ready-made program package
that provides easy to use menu-based or graphics-based
interfaces, An example is the user of a tax package that
basically stores a variety of personal financial data of tax
purposes. These users become very proficient in using a
specific software package.

Q5. Briefly discuss 10 advantages of


DBMS.

A5. 10 major advantages of DBMS are:-


i. Improved data sharing

An advantage of the database management approach is,


the DBMS helps to create an environment in which end
users
Pa g e | 9

have better access to more and better-managed data.Such


access makes it possible for end users to respond quickly to
changes in their environment.

ii. Improved data security

The more users access the data, the greater the risks of data
security breaches. Corporations invest considerable amounts
of time, effort, and money to ensure that corporate data are
used properly. A DBMS provides a framework for better
enforcement of data privacy and security policies.

iii. Better data integration

Wider access to well-managed data promotes an integrated


view of the organization’s operations and a clearer view of
the big picture. It becomes much easier to see how actions in
one segment of the company affect other segments.

iv. Minimized data inconsistency

Data inconsistency exists when different versions of the


same data appear in different places. For example, data
P a g e | 10

inconsistency exists when a company’s sales department


stores a sales representative’s name as “Bill Brown” and the

company’s personnel department stores that same person’s


name as “William G. Brown,” or when the company’s
regional sales office shows the price of a product as
$45.95 and its national sales office shows the same
product’s price as $43.95. The probability of data
inconsistency is greatly reduced in a properly designed
database.
v. Improved data access

The DBMS makes it possible to produce quick answers to


ad hoc queries. From a database perspective, a query is a
specific request issued to the DBMS for data
manipulation—for example, to read or update the data.
Simply put, a query is a question, and an ad hoc query is
a spur-of-the-moment question. The DBMS sends back
an answer (called the query result set) to the application.

vi. Improved decision making

Better-managed data and improved data access make it


possible to generate better-quality information, on which
better decisions are based. The quality of the
information generated depends on the quality of the
underlying data.
P a g e | 11

Data quality is a comprehensive approach to promoting the


accuracy, validity, and timeliness of the data. While the
DBMS does not guarantee data quality, it provides a
framework to facilitate data quality initiatives.

vii. Increased end-user productivity


The availability of data, combined with the tools that
transform data into usable information, empowers end users
to make quick, informed decisions that can make the
difference between success and failure in the global
economy.

viii. Data Backup and Recovery

This is another advantage of DBMS as it provides a strong


framework for Data backup, users are not required to
back up their data periodically and manually, it is
automatically taken care by DBMS. Moreover, in case of
a server crash, DBMS restores the Database to its
previous condition.

ix. Data Atomicity

An atomic transaction is one in which all of the database


actions occur or none of them do. It is the duty of DBMS
to
P a g e | 12

store a complete transaction in the database. If any


transaction is partially completed, then it rolls backs them.

x. Data Loss is almost eliminated

With DBMS, one can keep information for thousands of


years, provided we don’t see the doomsday. Data security
and very low storage cost (as compared to our previous
generations) in the current century cut any possibility of
Data Loss.

Q6. Answer the following:


a)Identify 10 informal (in english language not sql) queries
and update operations that you would expect to apply to
the database shown in Figure 1.2.
b)Also specify all the relationships among the records of
the database.
c)Cite some examples of integrity constraints that you think
can apply to the database
P a g e | 13

A6.

a) Informal Queries:-

Retrieve the list of all courses and grader of ‘Brown’.


Retrieve the list of student number and semester of
‘Smith’.
List the names of students who took ‘database’ courses in
fall 2005 and their grades in that section.
List the prerequisites of ‘data structures’ course.

Display the course_ name and credit_ hours of the


students whose major is ‘CS’

Update Operations:-

Change the class of ‘Brown’ to sophomore.

Create a new section for the ‘Discrete Mathematics’


course for their semester.
Enter a grade ‘B’ for ‘Smith’ in the ‘Intro to computer
science’ section of last semester.
change the year of semester ‘Spring’ to ‘06’.

Change the instructor to ‘king’ of the students whose


student_ number is ‘19’
P a g e | 14

b)
(1) Each SECTION record is related to a COURSE record.

(2)Each GRADE_REPORT record i s related to one


STUDENT record and one SECTION record.
(3)Each PREREQUISITE record relates two COURSE
records: one in the role of a course and the other in the
role of a prerequisite to that course.

c) We give a few constraints expressed in English .


Following each constraint, we give its type in the relational
database terminology
(i)The StudentNumber should be uni que for each
STUDENT record (key constraint).
(ii)The CourseNumber should be unique for each COURSE
record (key constraint).
(iii)A value of CourseNumber in a SECTION record must
also exist in some COURSE record (referential integrity
constraint).

(iv)A value of StudentNumber in a GRADE_REPORT


record must also exist in some STUDENT record
(referential integrity constraint).
P a g e | 15

(v)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).

(vi)Every record in COURSE must have a value for


CourseNumber (entity integrity constraint).
(viii) 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 th at
24 credits (general semantic integrity constraint)

Q7. What is the difference between controlled and


uncontrolled redundancy? Illustrate with examples.

A7. Redundancy is the state of being not or no longer


needed or useful. In the traditional approach, uncontrolled
redundancy in storing the same data/information many times
in the database leads to several problems. This leads to
Duplication of effort, Wastage of storage space and
inconsistent data.

Controlled
redundancy
P a g e | 16

A controlled redundancy is a necessary technique to use


redundant fields in a database. This speed ups the database
access and also improves the performance of queries.
Usually, the DBMS ensures the allocation of the data in the
records. It should have the capability to control this
redundancy in order to prohibit inconsistencies among the
files.

Uncontrolled redundancy

Redundancy occurs when the storage of the same data


occurs in multiple locations in the database. With
uncontrolled redundancy, many issues can occur including
inconsistent data such as multiple methods of data structure
such as order of birth date information, waste of storage
space and the duplication of effort of inputting data.
The difference between controlled redundancy and
uncontrolled redundancy is with controlled redundancy,
methods can be used to combine data that is input
automatically.
P a g e | 17

ASSIGNMENT 1
CHAPTER 2
Q1. Define the following terms:
a) Data model,
b) Data independence,
c) Client/Server architecture

A1.a) Data Models are fundamental entities to introduce


abstraction in a DBMS. Data models define how data is
connected to each other and how they are processed and
stored inside the system.

b)Data independence refers characteristic of being able to


modify the schema at one level of the database system
without altering the schema at the next higher level.

c)The basic client/server architecture is used to deal with


a large number of PCs, web servers, database servers and
other components that are connected with networks.
The client/server architecture consists of many PCs and a
workstation which are connected via the network.
P a g e | 18

Q2. Differentiate between the following:


a) Database schema and Database state,
b) Internal schema, Conceptual schema, External schema
c) Relational model, the Object model, and the XML model
d) Procedural and Non-procedural DMLs
e)Logical data independence and Physical data
independence
f) two-tier and three-tier client/server
architectures

A2. a)
Database Schema Database State

A database schema is the Database state refers to the


skeletal structure that represent content of a database at any
the logical view of all the point in time. A database
entire datasets defining how state provides the present
the data are organized and how state of the database and its
the relations among them are data. It can be considered
associated. as an extension of the
database schema
P a g e | 19

b)
Internal Schema Conceptual Schema External Schema

Internal Schema Conceptual External Schema


represents the schema maps internal represents data
physical storage of schema data to accessed by end
data on a disk or a the external schema. users or
physical storage application
device. programs, it
provides
customized
information to
the end users.

The internal A conceptual In external


schema is a very schema is a high- schema, Each
low-level level description of a view schema
representation of business's describes the
the entire informational needs. database part
database. It It typically that a
contains multiple includes only the particular user
occurrences of main concepts and group is
multiple types the main interested and
of internal record. relationships hides the
among them. remaining
database from
that user
group.
P a g e | 20

Relational Model Object Model XML Model

In the relational Independence of An XML document


model, the only classes: classes can contains information
types of be reorganized about the
relationships that can without affecting the relationship of data
be defined are mode of using items to each other
parent table and in the form of the
dependent table hierarchy.
relationships.

In the relational The structure of data An XML document


model, the content of may be complex, contains not only the
the data is defined involving different data, but also
by its column types of data. tagging for the data
definition. All data that explains what it
in a column must is. A single
have the same type document can have
of data. different types of
data.

For relational data, The data for an For an XML


the order of the rows object can be document, the order
is not guaranteed interrelated and in which data items
unless you specify stored together, so are specified is
an order by clause that they may all be assumed to be the
on one or more accessed by the order of the data in
columns. access mechanism. the document.
P a g e | 21

d)

Procedural DML’s Non- Procedural DML’s

In procedural languages, the In the non-procedural


program code is written as languages, the user has to
a sequence of instructions. specify only “what to do”
User has to specify “what to and not “how to do”. It is
also known as an applicative
do” and also “how to do”
or functional language.

These instructions are It involves the development


executed in the sequential of the functions from other
order. These instructions are functions to construct
written to solve specific more complex functions.
problems.

Examples of Procedural Examples of Non-Procedural


languages: languages:
FORTRAN, COBOL, SQL, PROLOG, LISP.
ALGOL, BASIC, C and
Pascal.
P a g e | 22

e)

Logical Data Independence Physical Data


Independence

Logical Data Independence Physical Data


Independence modifies the logical schema modifies the
physical schema without causing the
without causing the application program to be
application program to be rewritten.
rewritten.

Logical Data Independence is Physical Data


Independence difficult to achieve. is easy to
achieve.

Modifications at the logical Modifications at the


physical level are necessary required. level
are occasionally
required.
P a g e | 23

f)
Two – Tier Client Three – Tier Client
Architecture Architecture

It is a Client-Server It is a Web-based
Architecture. application.

In two-tier, the application In three-tier, the application


logic is either buried inside logic or process resides in
the user interface on the the middle-tier, it is
client or within the database separated from the data and
on the server the user interface.

Two-tier architecture Three-tier architecture


consists of two layers: Client consists of three layers:
Tier and Database (Data Client Layer, Business Layer
Tier). and Data Layer.

Q3. Explain the three-schema architecture and mappings


among schema levels. How is this architecture supported by
schema definition languages?
P a g e | 24

A3. Features of Three Schema Architecture:-


 This framework is used to describe the structure of a
specific database system.

 The three schema architecture is also used to separate


the user applications and physical database.

 The three schema architecture contains three-levels. It


breaks the database down into three different categories.

The Three Schema Architecture is as follows:-


P a g e | 25

Q4. Name few software with which DBMS


interacts?

A4.

 SolarWinds Database Performance Analyzer


 DbVisualizer
 ManageEngine Applications Manager
 Altibase
 Oracle RDBMS
 IBM DB2
 Microsoft SQL Server
 SAP Sybase ASE
 Teradata
 ADABAS
 MySQL
 FileMaker
 Microsoft Access
 Informix
 SQLite
P a g e | 26

ASSIGNMENT 1
CHAPTER 5

Q1. Define the following terms:


a) Domain,
b) n-tuple,
c) Degree of a relation

A1.
a) A domain is a unique set of values permitted for an
attribute in a table. For example, a domain of month-of-
year can accept January, February….December as
possible values, a domain of integers can accept whole
numbers that are negative, positive and zero.

b) A single entry in a table is called Tuple or Record or


Row.
A tuple in a table represents a set of related data. In
mathematics, a tuple is an ordered list of elements. Each
n-tuple is an ordered list of n values where each value
is an element of domain or is a special NULL value.
P a g e | 27

c) The degree of a relation is the number of attributes


(columns) in the given table. It is also called as Arity.

Q2. Differentiate between


following:
a) Key and Superkey
b) Intension and Extension

A2. a)
Key Super Key

An SQL key is either a single Super key is a single key or a


column (or attribute) or a group of multiple keys that
group of columns that can can uniquely identify tuples
uniquely identify rows (or in a table.
tuples) in a table.

b)
P a g e | 28

Intensio Extensio
n n

It is the number of tuples It is the number of tuples


present in a table at any present in a table at any
instance. This is time instance. This is time
dependent. dependent.

Q3. Why are tuples not ordered and duplicate tuples


not allowed in a relation?

A3. Duplicate tuples are not allowed in a relation because


they created redundancy of data base which makes the data
processing like querying, inserting, deleting, updating etc
slow the speed of data base.

Q4. Why do we designate one of the candidate keys of


a relation to be the primary key?
P a g e | 29

A4. Because regardless of how many candidate keys a


relation may have, only one field can actually be used as the
primary key for a given table. So designating a primary key
is forcing you into choosing the one value - among all
possibilities - that will determine a unique row in your table.
Officially designating it a primary key also has the effect of
ensuring that no two values in that column can ever be the
same and allowing for establishing foreign key constraints
between that value and values in other tables

Q5. What is the significance of NULL values in relations?

A5.
 In a database, zero is a value which has meaning, so the
value NULL became is a special marker to mean that no
value exists. In that sense, NULL does not refer to a
memory location, as it does for programming
languages. In a database, the NULL value indicates a
lack of a value.
 Any column that is part of a KEY must not allow
NULLs, but for other fields, it's completely up to you.
Including the NOT NULL clause next to your column
definitions at table creation time will force the user
to
P a g e | 30

include a value for that column in INSERT and


UPDATE operations.
.

Q6. Explain entity integrity and referential


integrity constraints with the help of examples.

A6. The concept of Entity Integrity refers to the fact that in a


relational databases schema every relation must have a
primary key that is defined by a set of field (or column)
names and ensures that it holds for every record in the
relation that all these fields do not contain a NULL value,
and every record in the relation has a unique combination of
values in these fields. This corresponds to the intuition that
the records refer to entities that are clearly defined and
identified, and so their identifying attributes must be
completely known and unique. The concept of Referential
Integrity refers to the fact that if there is a foreign key in a
relation R that points to a relation S, then it must hold for
every record in R that the fields that make up the foreign
key either (1) all contain NULL values or (2) the
combination of their values appears as the key of a record in
S. This corresponds to the intuition that the records in R
either are not referencing a record in S (and so all foreign
key fields are NULL) or indeed reference a record in S
(and so the corresponding record in S exists).
P a g e | 31

Q7. What is a transaction? How does it differ from an


Update operation?

A7. A transaction is a program in execution that involves


various operations that can be done on the database. The
operations that are included in a transaction are as follows:
• Reading data from the database.
• Deleting a tuple from the database.
• Inserting new tuples to the database
• Updating values of existing tuples in the database.
The main difference between transactional data and
operational data is that transactional data is the data that
describes business events of the organization while
operational data is the data that is used to manage the
information and technology assets of the organization.
P a g e | 32

Q8. Consider the following six relations for an order


processing database application in a company:
CUSTOMER(Cust#, Cname, City)
ORDER(Order#, Odate, Cust#, Ord_amt)
ORDER_ITEM(Order#, Item#, Qty)
ITEM(Item#, Unit_price)
SHIPMENT(Order#, Warehouse#, Ship_date)
WAREHOUSE(Warehouse#, City)
Here, Ord_amt refers to total dollar amount of an order;
Odate is the date the order was placed; and Ship_date is the
date an order (or part of an order) is shipped from the
warehouse. Assume that an order can be shipped from
several warehouses. Specify the primary key and foreign
keys for this schema, stating any assumptions you make.
What other constraints can you think of for this database?

A8.
CREATE TABLE CUSTOMER ( CUST# NUMBER(5),
CNAME VARCHAR (15) NOT NULL,
CITY VARCHAR (15),
PRIMARY KEY(CUST#) );
P a g e | 33

CREATE TABLE ORDER ( ORDER# NUMBER(5) ,


ODATE DATE,
CUST# NUMBER(5),
REFERENCES CUSTOMER(CUST#), ORD_AMT
NUMBER(5) );

CREATE TABLE ITEM ( ITEM NUMBER(5)


CONSTRAINT PK2
PRIMARY KEY, UNITPRICE NUMBER(9,2) NOT NULL
);

CREATE TABLE ORDER_ITEM ( ORDER# NUMBER


(5),
ITEM NUMBER (5),
QTY NUMBER(4),
FOREIGN
KEY(ORDER#)
REFERENCES CUSTORDER(ORDER#),
FOREIGN KEY(ITEM) REFERENCES ITEM(ITEM),
PRIMARY KEY(ORDER#,ITEM) );

CREATE TABLE WAREHOUSE ( WAREHOUSE#


NUMBER(5),
CITY VARCHAR2(15),
P a g e | 34

PRIMARY KEY(WAREHOUSE#) );

CREATE TABLE SHIPMENT ( ORDER# NUMBER(5),


WAREHOUSE# NUMBER(5),
SHIP_DATE DATE,
FOREIGN KEY(ORDER#) REFERENCES
CUSTORDER(ORDER#),
FOREIGN KEY(WAREHOUSE#) REFERENCES
WAREHOUSE(WAREHOUSE#),
PRIMARY KEY(ORDER#,WAREHOUSE#) );

Q9. 5.9. 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)
P a g e | 35

Specify the primary key and foreign keys for this schema,
stating any assumptions you make.

A9.

CREATE TABLE STUDENT ( REGNO VARCHAR(10),


NAME VARCHAR(14),
MAJOR VARCHAR(10),
BDATE DATE,
PRIMARY
KEY(REGNO) );

CREATE TABLE COURSE ( COURSE# NUMBER(4),


CNAME VARCHAR(14),
DEPT VARCHAR(10),
PRIMARY KEY(COURSE#) );

CREATE TABLE ENROLL ( REGNO VARCHAR(10),


COURSE# NUMBER(4),
SEM NUMBER(4),
P a g e | 36

MARKS NUMBER(3),
PRIMARY KEY(REGNO,COURSE#,SEM),
FOREIGN KEY(REGNO) REFERENCES
STUDENT(REGNO),
FOREIGN KEY(COURSE#) REFERENCES
COURSE(COURSE#) );

CREATE TABLE TEXT ( ISBN NUMBER(5),


BOOK_TITLE VARCHAR(13) NOT NULL,
PUBLISHER VARCHAR(12),
AUTHOR VARCHAR(12),
PRIMARY KEY(ISBN) );
P a g e | 37

ASSIGNMENT 1
CHAPTER 6
Q1. Consider the database schema shown below. What are
the entity and referential integrity constraints that should
hold on the schema? Write appropriate SQL DDL
statements to define the database.

STUDENT
Roll_no
Student_name
Class
Major

COURSE
Course_no
Course_name
Credit_hrs
Dept

PREREQUI
SITE
Course_no
Prerequisite_no
P a g e | 38

SECTION
Section_id Course_no
Sem
Year
Instructor

GRADE
_REPO
RT
Roll_no
Section_id
Grade

CREATE TABLE STUDENT (Name VARCHAR(30) NOT


A1.
NULL,
StudentNumber INTEGER NOT NULL,
Class CHAR NOT NULL,
Major CHAR(4),
PRIMARY KEY (StudentNumber));

CREATE TABLE COURSE ( CourseName


VARCHAR(30) NOT NULL,
CourseNumber CHAR(8) NOT NULL,
P a g e | 39

CreditHours INTEGER,
Department CHAR(4),
PRIMARY KEY (CourseNumber),
UNIQUE (CourseName));

CREATE TABLE PREREQUISITE ( CourseNumber


CHAR(8) NOT NULL,
PrerequisiteNumber CHAR(8) NOT NULL,
PRIMARY KEY (CourseNumber, PrerequisiteNumber),
FOREIGN KEY (CourseNumber) REFERENCESCOURSE
(CourseNumber),
FOREIGN KEY (PrerequisiteNumber)
REFERENCESCOURSE (CourseNumber));

CREATE TABLE SECTION ( SectionIdentifier) INTEGER


NOT NULL,
CourseNumber CHAR(8) NOT NULL,
Semester VARCHAR(6) NOT NULL,
Year CHAR(4) NOT NULL,
Instructor VARCHAR(15),
P a g e | 40

PRIMARY KEY (SectionIdentifier),


FOREIGN KEY (CourseNumber) REFERENCESCOURSE
(CourseNumber) );

CREATE TABLE GRADE_REPORT ( StudentNumber


INTEGER NOT NULL,
SectionIdentifier INTEGER NOT NULL,
Grade CHAR,
PRIMARY KEY (StudentNumber,
SectionIdentifier),
FOREIGN KEY (StudentNumber)
REFERENCESSTUDENT (StudentNumber),
FOREIGN KEY (SectionIdentifier)
REFERENCESSECTION (SectionIdentifier));

Q2. Consider the relational database schema shown below.


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
P a g e | 41

primary key attribute value in a referenced tuple. Justify


your choices.

Reference_Book
Book#
Title
Publisher

Author
Book#
Author_name

Publisher
Name
Address
Phone

Book_Co
pies
Book#
P a g e | 42

Branch#
No_of_copies

Branch
Branch# Branch_name
Address

Borrower
Card_no Name
Address Phone

A2. REJECT should be chosen, since it will not permit


automatic changes to happen that may be unintended.

BOOK_AUTHORS.(BookId) --> BOOK.(BookId)


CASCADE on both DELETE or UPDATE .hence, if a
BOOK is deleted, or the value of its BookId is updated
(changed), the deletion or change is automatically
propagated to thereferencing BOOK_AUTHORS
tuples)BOOK.
P a g e | 43

(PublisherName) --> PUBLISHER.(Name)REJECT on


DELETE (we should not delete a PUBLISHER tuple which
has existing BOOK tuples that reference the PUBLISHER
CASCADE on UPDATE (if a PUBLISHER's Name is
updated, the change should be propagated automatically to
all referencing BOOK tuples)

BOOK_LOANS.(BookId) --> BOOK.(BookId)CASCADE


on both DELETE or UPDATE (if a BOOK is deleted, or the
value of its BookId is updated (changed), the deletion or
change is automatically propagated to the referencing
BOOK_LOANS tuples)

BOOK_COPIES.(BookId) --> BOOK.(BookId)CASCADE


on both DELETE or UPDATE (if a BOOK is deleted, or the
value of its BookId is updated (changed), the deletion or
change is automatically propagated to the referencing
BOOK_COPIES tuples)

BOOK_COPIES.(BranchId) -->
LIBRARY_BRANCH.(BranchId)CASCADE on both
DELETE or UPDATE (if a LIBRARY_BRANCH is
deleted, or the value of its BranchId is updated
(changed),
P a g e | 44

the deletion or change is automatically propagated to the


referencing BOOK_COPIES tuples

BOOK_LOANS.(BranchId) -->
LIBRARY_BRANCH.(BranchId)CASCADE on both
DELETE or UPDATE (if a LIBRARY_BRANCH is
deleted, or the value of its BranchId is updated (changed),
the deletion or change is automatically propagated to the
referencing BOOK_LOANS tuples

Q3. Write the following queries in SQL on the relational


database schema shown below.

EMPLOYEE
Ssn Fname Lname
Bdate
Address
Salary
P a g e | 45

Super_ssn Dno

DEPT
Dnum
Dname
Mgr_s
sn
Mgr_st
artdate

WOR
KS_O
N
Wssn
Pno
Hours

PROJ
ECT
Pnum
Pname

Dnum
P a g e | 46

Bdate
Relationship

a.List the names of all employees who have a dependent


with the same first name as themselves.
b.Fetch the names of all employees in Dept ‘Sales’ who
work less than 40 hours per month on the project ‘ITEM-X’.
c.Find the names of all employees who are directly
supervised by ‘ Mr. Verma’.

A3.
a)SELECT E.Fname||E.Lname as ‘Name’
FROM EMPLOYEE E, DEPENDENT D
WHERE E.Fname = D.DE_name;

b) SELECT E.Fname||E.Lname as ‘Name’


FROM EMPLOYEE E , WORKS_ON W , DEPT D,
PROJECT P
WHERE D.Dname = ‘Sales’ and W.Hours
P a g e | 47

c) SELECT Fname||Lname as ‘Name’


FROM EMPLOYEE
WHERE Supervisor_ Name = ‘Mr.
Verma’

Q4. Write SQL update statements to do the following on


the database schema shown in question 6.1.
a.Insert a new student, <‘Mary’, 17, 1, ‘Eng’>, in the
database.
b. Change the class of student ‘Sara’ to 2.
c.Insert a new course, <‘Software Engineering’, ‘cs123’,
1, ‘cs’>.
d.Delete the record for the student whose name is ‘Sunil’
and whose student number is 22.

A4.
P a g e | 48

a) Insert into STUDENT values <‘Mary’, 17 , 1 , ‘Eng’>

b)UPDATE TABLE STUDENT


Set Class = 2
where Student_Name = ‘Sara’

c)Insert into COURSE(Course_no., Course_Name,


Credit_Hours, Dept)
Values(‘CS123’ , ‘Software Engineering’ , 1 , ‘CS’)

d) DELETE FROM STUDENT


Where Student_Name = ‘Sunil’ AND Roll_no. =
22

You might also like