Вы находитесь на странице: 1из 5


School:B Department:CSE/IT
Course No: CSE301
Course Title: Database Management System
Date of Allotment:8-02-2011
Date of Submission:22-02-2011
Submitted to:Ms. Monica Sood
Submitted by:
Manvi Kalra

Q. 1 create a package which includes:
a)function to return the square of the number if number is posotive else return
an error code 100
b)procedure to calculate the simple interest by passing the values of
principal,rate and time
Answer: Procedure Proc1 is
p number(9,2) ;
n number(9,2) ;
r number(9,2) ;
si number(9,2) := 0;
ci number(9,2) := 0;
p := &principal_amount;
n := &no_of_years;
r := &rate_of_interest;
si := p*n*r/100;
ci := p*(1+r/100)**n;
dbms_output.put_line('simple interset =' ||si);
dbms_output.put_line('compound interset =' ||ci);
Function Func1 return num is
P num(10);
S num(10);
If p>0 then
Q. 2 List two reasons why null values might be introduced into the database.

Answer: When the information is not available at present but may be updated later
from the same form or other interfaces. Using null value, you can keep those
columns without inserting any value. This is usually done if you currently dont have a
value and in future you may have. If not null, you have to put some value into it.

We can explain with an example.Suppose you are an employee in an company and

you have applied for passport right now.And they need to fill the passport information
which you can't provide right now.But you can provide once you get the passport.In
such case,the field is left as null(means no value) and later they can fill it.Some
informations which are required cannot be provided right now,but in future they will
be filled. Also we can leave such field as null,instead of altering the table definition at
the time,when the details are obtained.

NULL is also an SQL reserved keyword used to identify the Null special marker.

Q. 3 “Does indexing play a role in database management system”. Explain

your answer with example.


A database index is a data structure that improves the speed of data retrieval
operations on a database table at the cost of slower writes and increased storage
space. Indexes can be created using one or more columns of a database table,
providing the basis for both rapid random lookups and efficient access of ordered
records. The disk space required to store the index is typically less than that required
by the table (since indices usually contain only the key-fields according to which the
table is to be arranged, and exclude all the other details in the table), yielding the
possibility to store indices in memory for a table whose data is too large to store in

In a relational database, an index is a copy of one part of a table. Some databases

extend the power of indexing by allowing indices to be created on functions or
expressions. For example, an index could be created on upper(last_name), which
would only store the upper case versions of the last_name field in the index. Another
option sometimes supported is the use of "filtered" indices , where index entries are
created only for those records that satisfy some conditional expression. A further
aspect of flexibility is to permit indexing on user-defined functions, as well as
expressions formed from an assortment of built-in functions. Indices may be defined
as unique or non-unique. A unique index acts as a constraint on the table by
preventing duplicate entries in the index and thus the backing table.

Indices can be classified as:



Example:. Consider the following SQL statement: SELECT first_name FROM people
WHERE last_name = 'Smith';. To process this statement without an index the
database software must look at the last_name column on every row in the table (this
is known as a full table scan). With an index the database simply follows the B-tree
data structure until the Smith entry has been found; this is much less computationally
expensive than a full table scan.


Q. 4 Explain the role of virtual relations in relational database?And how we

combine relations for producing desired information?

A relational database matches data by using common characteristics found within

the data set. The resulting groups of data are organized and are much easier for
many people to understand. Strictly, a relational database is a collection of relations
(frequently called tables). Other items are frequently considered part of the
database, as they help to organize and structure the data, in addition to forcing the
database to conform to a set of requirements.

A relation is defined as a set of tuples that have the same attributes. A tuple usually
represents an object and information about that object. Objects are typically physical
objects or concepts. A relation is usually described as a table, which is organized into
rows and columns. All the data referenced by an attribute are in the same domain
and conform to the same constraints.

The relational model specifies that the tuples of a relation have no specific order and
that the tuples, in turn, impose no order on the attributes. Applications access data
by specifying queries, which use operations such as select to identify tuples, project
to identify attributes, and join to combine relations. Relations can be modified using
the insert, delete, and update operators. New tuples can supply explicit values or be
derived from a query. Similarly, queries identify tuples for updating or deleting. It is
necessary for each tuple of a relation to be uniquely identifiable by some
combination (one or more) of its attribute values. This combination is referred to as
the primary key.
In a relational database, all data are stored and accessed via relations. Relations
that store data are called "base relations", and in implementations are called
"tables". Other relations do not store data, but are computed by applying relational
operations to other relations. These relations are sometimes called "derived
relations". In implementations these are called "views" or "queries". Derived relations
are convenient in that though they may grab information from several relations, they
act as a single relation. Also, derived relations can be used as an abstraction layer.

Q. 5: Suppose there are two relations r and s, such that the foreign key B of r

the primary key A of s. Describe how the trigger mechanism can be used

to implement the on delete cascade option, when a tuple is deleted from s.


We define triggers for each relation whose primary-key is referred to by the foreign-
key of some other relation. The trigger would be activated whenever a tuple is
deleted from the referred-to relation. The action performed by the trigger would be to
visit all the referring relations, and delete all the tuples in them whose foreign-key
attribute value is the same as the primary-key attribute value of the deleted tuple in
the referred-to relation. These set of triggers will take care of the on delete cascade

Q. 6: Specify the following views in SQL on the COMPANY database schema .

a. A view that has the department name, manager name, and manager salary
for every department.

b. A view that has the employee name, supervisor name, and employee salary
for each employee who works in the ‘Research’ department.

c.A view that has project name, controlling department name, number of
employees, and total hours worked per week on the project for each project.

d.A view that has project name, controlling department name, number of
employees, and total hours worked per week on the project for each project
with more than one employee working on it.

a. Create view view1 as select dept_name,man_name,man_sal from manager where
group by dept_name;

bCreate view view2 as select emp_name,sup_name,emp_sal from employee where

dept_name= “research”;

c. Create view view3 as select proj_name,cont_name,no_emp , totalhours from

where project group by proj_name

d. Create view view4 as select proj_name,control_dept,no_emp,totalhours from

project where no_emp>1 group by project ;