You are on page 1of 5

ASSIGNMENT no 2

DATABASE MANAGEMENT
SYSTEMS
CSE-301

SUBMITTED TO- SUBMITTED BY:-

LECT. : Monica sood SANDEEP KUMAR

SECTION:-B1801

Roll no=B35

REG NO.:-10808283

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.
Ans..

CREATE OR REPLACE PACKAGE database AS

FUNCTION square (num IN number) return number


IS/AS
BEGIN
IF num>0
THEN
RETURN (num*num);
ELSE
Dbms_output.put_line(error code 100)
ENDIF
END square
CREATE OR REPLACE PROCEDURE data( p IN number, r IN number, t IN number, result
OUT number)
BEGIN
data := p*n*r/100
dbms_output.put_line(interest =’data’);

END data

END database

Q. 2 List two reasons why null values might be introduced into the database.

Ans Two reasons why null values might be introduced into the database are as follow-

1. To Allowing NULL values into your columns introduces a new degree of uncertainty into
your database. For example if two or more programmers work on the same table with
NULL values in a database it allowed programmer to could end up with as many different
results .
2. In the relational model it states that every attribute has a value for a given occurence in
row/tuple. Where as NULL is not a value but it is something unknown. For example If a
row is inserted but no value is included for a column that allows null values, the database
engine supplies the value NULL. A column defined with the keyword NULL also accepts
an explicit entry of NULL from the user no matter what data type it is or if it has a default
associated with it. The value NULL should not be placed within quotation marks because it
will be interpreted as the character string 'NULL' rather than the null value.
3. The column which contain null values can also used for joining two tables and also used in
making virtual relation.

Q. 3 “Does indexing play a role in database management system”. Explain your answer with
example.
Ans . Yes, indexing play a role in database management system.following are the reason how it
play a important role in database management.

1. The indexing helps in improving the search time of the data through the use of pointers
2. It also improves accesss time to the data in the specified table in the memory.
3. An index is made up of a set of pages that are organized in a B-tree structure. This
structure is hierarchical in nature, with the root node at the top of the hierarchy and the leaf
nodes at the bottom.

Part-B

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


relations for producing desired information?

Ans A view is quite easy to define. It is not anymore than a named a virtual table. You can select
data, alter data, remove data and all other things you can do with a table with some limitations. But
there is a difference between a view and a table. The data accessible through a view is not stored in
the database as its own object. It’s stored in the underlying tables that make up the view.Aveiw is
an imaginary table that is created from some other base table. In stead of allowing a user to access
all coloumns of a table , user will allow to access only some specific column through virtual
relation . the basic function of view is to provide security to the data by restricting the access to a
base table . there can be several view be created from the same base table.

we combine relations for producing desired information by using the view statement byusing
where function. The syntax for creating a VIEW are as follow-

CREATE VIEW view_name AS


SELECT columns
FROM table
WHERE predicates;

An example of virtual relation are as follow-

CREATE VIEW sup_orders AS SELECT suppliers.supplier_id, orders.quantity, orders.price


FROM suppliers, orders WHERE suppliers.supplier_id = orders.supplier_id and
suppliers.supplier_name = 'IBM';

This would create a virtual table based on the result set of the select statement. This query can be
view as follows:

SELECT * FROM sup_orders;

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 to implement the on
delete cascade option, when a tuple is deleted from s .

Ans when a tuple is fired then it is automated process in which we only give instruction and
relation are joined with a common tuple which would help in relating the relations and when a
cascaded deletion,updation or insertion is there we would delelte all the corresponding entries to
that relation. 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.

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.

Ans Create view dept as select deptname, man_name, man_salary from company

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

Ans Create view research as select emp_name, sup_name, and emp_sal from company where
department =’research’;

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.

Ans Create view pro as select dep_name, no_emp, thours from company;

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.

Ans Create view main as select pro_name, dept_name, no_emp, thours ,count * (empno) from
company where no_emp >1.

You might also like