Sie sind auf Seite 1von 6

1

ASSIGNMENT -2

OF

DATABASE MANAGEMENT SYSTEMS

SUBMITTED TO: SUBMITTED BY:


Ms. Preetpal
GAGANPREET KAUR
ROLL NO: 42

SECTION: B1803
2

PART-A

Question 1: Why do we use indexing? Give a suitable example in support of your answer.
Ans: -
Indexing: - In indexing we index the whole data and apply indexing algorithms to search the
data so it increases the rate of searching in database so it save time as well as resources.
• In large databases, this can reduce query time/cost by orders of magnitude. The simplest
form of index is a sorted list of values that can be searched using a binary search with an adjacent
reference to the location of the entry, analogous to the index in the back of a book.
• An index for a file in a database system works in much the same way as the index in a
textbook. The words in the index are in sorted order, making it easy to find the word we want.
Moreover, the index is much smaller than the book, further reducing the effort needed.
• For example:- to retrieve a student record given an ID, the database system would look up
an index to find on which disk block the corresponding record resides, and then fetch the disk
block, to get the appropriate student record even though keeping the index sorted reduces the
search time, finding a student can still be rather time – consuming. Instead, more sophisticated
indexing techniques may be used.
• Two basic kinds of indices:-

 Ordered indices: - Each index structure is associated with a particular search key.
Just like the index of a book or a library catalog, an ordered index stores the values of the search
keys in sorted order, and associates with each search key the records that contain it
 (II) Hash indices: - Based on a uniform distribution of values across a range of
buckets. The bucket to which a value is assigned is determined by a function, called a hash
function.

Question 2: Under what circumstances, we will use foreign key? Give an example.
Ans: - A foreign key is a set of attributes in a referencing relation, such that for each tuple in the
referencing relation, the values of the foreign key attributes are guaranteed to occur as the
primary key value of a tuple in the referenced relation

EXAMPLE- say we have two tables, an EMP_details table that includes all employee data, and
an ORDERS table that includes all employee orders. The constraint here is that all orders must be
associated with a customer that is already in the EMP_details table. In this case, we will place a
foreign key on the ORDERS table and have it relate to the primary key of the EMP_details table.
This way, we can ensure that all orders in the ORDERS table are related to an employee in the
EMP_details table. In other words, the ORDERS table cannot contain information on an
3

employee that is not in the EMP_details table. The structure of these two tables will be as
follows:

Table EMP_details Table ORDERS

column name characteristic


SID Primary Key
Last_Name
First_Name
column name Characteristic
Order_ID Primary Key
Order_Date
Employee_SID Foreign Key
Amount

Question3: Produces a new relation with some of the attributes of relation and remove
duplicate tuples, give two different examples.
Answer:-

Customer_name Account_number
HAYES a-102
JACK A101
JACK A201
JONAS A-217
LOHAN A-222
SMANTHA A215
TARKAN A-305

THE DEPOSITER RELATIONSHIP

CUSTOMER_NAME LOAN_NUMBER
ADAMS L-16
CURRY L-93
HAYES L-15
JACKSON L-14
JONAS L-17
4

SMANTHA L-1
SMANTHA L-23
WILLIAMS L-17

THE BORROWER RELATION

1:-s is a query to find the name of all the customer who have either an account or loan,or both

Suppose we have to find all the names of all the customer with a loan in the bank
Then ∏customer_name(borrower)

Now we want to find the name of all customers having an account in the bag
∏customer_name(depositer)

Now by combining the two factor we can find the desired result
∏customer_name(borrower)U∏customer_name(depositer)

2:- This is the relation to find those tuples that are in one relation but not in other.
∏customer_name(depositer)-- ∏customer_name(borrower)

.PART-B

Question 4: Can we use a virtual table for security purpose? Justify your answer and give
an example to create a view.
Answer:-. Unlike ordinary tables (base tables) in a relational database, a view does not form part
of the physical schema: it is a dynamic, virtual table computed or collated from data in
the database. Changing the data in a table alters the data shown in subsequent invocations of the
view.
Control of access to sensitive information is of concern to managers, information
officers, DBAs, and application developers, among many others. Selective access control based
on a user's level of security clearance can ensure confidentiality without overbroad limitations.
This level of access control enables confidence that sensitive information will be unavailable to
unauthorized persons even while general users have access to needed information, sometimes in
the same tables.Data can be viewed as sensitive for many different reasons.

Examples include personal and private matters or communications, professional trade secrets,
company plans for marketing or finance, military information, or government plans for research,
purchases, or other actions. Allowing information to be seen or used by inappropriate persons
can be embarrassing, damaging, or dangerous to individuals, careers, organizations, agencies,
governments, or countries.

DBMS obviates the need for such measures by enabling row-level access control, based on the
virtual private database technology of . It controls access to the contents of a row by comparing
that row's label with a user's label and privileges. Administrators can easily add selective row-
restrictive policies to existing databases by means of the easy-to-use graphical interface called
Oracle Policy Manager. Developers can readily add label-based access control to their
applications.
5

Question 5: Write an SQL query without using a with clause , to find all branches where
the total account deposit is less than the average total account deposit at all branches
a) Using a nested query in the from clause?
Answer:- select count(distinct(account_number) from account order by branch_name where
count(distinct(account_number)<all(select avg(count(distinct(account_number) from account
order by branch_name);

b) Using a nested query in a Having clause ?


Answer:- select count(distinct(account_number) from account group by branch_name having
count(distinct(account_number)<all(select avg(count(distinct(account_number) from account
group` by branch_name);

Question 6: Consider the table EMPLOYEE and Department with following fields:
Employee( Emp_id,Emp_name, Dept_no, salary)
Department(dep_no, Dept_name,Location)
Perform the following computations on table data:
a) List all the employees whose location is ‘Pune’ and dept_name is ‘Computer’.

Answer: ∂ stands for sigma. ∩ stands for and


(∂department_name=”cse”∩ location=”pune”(EMPLOYEE x department))

b) Count the total number of departments. Also count the total number of employees whose
dept_name is ‘computer’ .

Answer:Gcount(dept_name)(department)Gcount(emp_name(∂department.dept_no=
EMPLOYEE.dept_no(∂dept_name=”cse”(EMPLOYEE x department))))

c) Add a new department ‘R&D’ in the database.


Answer: Department<----- department U (<dept_no>,”R&D”<location>

d) List the names of employees whose salary is greater than 50000 and dept_ name is
‘computer'.
Answer:Πemp_name(∂employee.dept_no=department.dept_no(∂dept_name=”computer”∩
salary>50000(EMPLOYEE X department)))

e) List the names of employees having maximum and minimum salary


Answer:
Πsalary(EMPLOYEE)-
6

ΠEMPLOYEE.salary(∂EMPLOYEE.salary<d.salary(EMPLOYEEρd(EMPLOYEE)))
Πsalary(EMPLOYEE)-ΠEMPLOYEE.salary(∂EMPLOYEE.salary>d.salary(EMPLOYEEX
ρd(EMPLOYEE)))

f) Now change the department name from ‘computer’ to ‘software design’, wherever
applicable in the table.
Answer:
DepartmentΠdept_no,dept_name=”softwaredesign”,location(∂dept_name=”computer”)
EmployeeΠemp_id,emp_name,dept_no=(Πdept_no(∂dept_name=”software design”)),salary

Das könnte Ihnen auch gefallen