Beruflich Dokumente
Kultur Dokumente
School:B Department:CSE/IT
Course No: CSE301
Course Title: Database Management System
Section:B1801
Date of Allotment:8-02-2011
Date of Submission:22-02-2011
Submitted to:Ms. Monica Sood
Submitted by:
Manvi Kalra
RB1801A21
10802591
Part-A
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
declare
p number(9,2) ;
n number(9,2) ;
r number(9,2) ;
si number(9,2) := 0;
ci number(9,2) := 0;
begin
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);
end;
/
Function Func1 return num is
Declare
P num(10);
S num(10);
Begin
If p>0 then
S=p*p;
return(s);
Else
DBMS_OUTPUT.PUT_ERROR(100);
End
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.
NULL is also an SQL reserved keyword used to identify the Null special marker.
Answer:
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
memory.
A)Non-clustered
B)clustered
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.
Part-B
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
references
the primary key A of s. Describe how the trigger mechanism can be used
answer:
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
operation.
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.
Answer:
a. Create view view1 as select dept_name,man_name,man_sal from manager where
group by dept_name;