Sie sind auf Seite 1von 4

*****-----------***********----------*********------------******

CSE 301 : Database Management System


HomeWork -2
Homework Title / No. : 2 Course Code : CSE 301
Course Instructor : Miss. Cherry Khosla
Date of submission : 24th –feb-2011
Student’s Roll No: RD 1804-B- 48 Section No. : D1804
REG NO. -10800826
Declaration:
I declare that this assignment is my individual work. I have not copied from any
other student’s work or from any other source except where due acknowledgment is
made explicitly in the text, nor has any part been written for me by another per
son.

ANOOP PRASAD YADAV


Student’s Signature :
Evaluator’s comments: __________________________________________________________
______

Marks obtained : ___________ out of ______________________

*********-----------***********----------*********------------******

Q-1 Teacher (U_id, T_Name, Course, salary)


Using tuple calculus solves the following queries:
a) Find all the tuples in a teacher relation.
b) Find those tuples for which salary of the teacher is greater than 20000.
c) Find the stu_id’s and courses of all the teachers.
Ans:-a). {t|t€Teacher}
b).{t|t€Teacher^t[Salary]>20000}
c). {t|┐s €Teacher(t[stu_id’s]=t[courses]=s{stud-id’s}=s{courses}}

Q-2 Why do we use indexing? Give a suitable example in support of your answe
r.
Ans:-
An index can be defined as a small table which has only two columns. The first
columncontains a copy of the primary or candidate key of a table and the second
column contains aset of pointers holding the address of the disk block where tha
t particular key value can befound.The main advantage of indexing lies is that
index makes search operation perform very fast.Example:Let us consider a table
has a several rows of data, each row is 10 bytes wide. If youwant to search for
the record number 70, the management system must thoroughly read eachand every r
ow and after reading 99x10 = 990 bytes it will find record number 70. If we have
an index, the management system starts to search for record number 70 not from t
he table,but from the index. The index, containing only two columns, may be just
4 bytes wide in eachof its rows. After reading only 99x4 = 396 bytes of data fr
om the index the managementsystem finds an entry for record number 70, reads the
address of the disk block where recordnumber 70 is stored and directly points a
t the record in the physical storage device. The resultis a much quicker access
to the record (a speed advantage of 990:396).
Considering these advantages of indexing we must say that indexing not only play
s role butplays a vital role in database management system

Q-3 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 SQL queries on table data:
a) Select * from employee where location=’punjab’ and dept name=’computer’;
c) Alter table employee add column r&d nvarchar(16);
d)select * from employee where salary>50,000;
f)update employee set ‘computer’=’software design’ where name=’kiran’;

Q-4 How Views are created in Database? Give examples of read-only view and u
pdatable views.
Ans:-
Views:
Unlike ordinary tables (base tables) in a relational database, a view does not f
orm part of thephysical schema: it is a dynamic, virtual table computed or colla
ted from data in the database.A SQL View is a virtual table, which is based on S
QL SELECT query. Essentially a view isvery close to a real database table (it ha
s columns and rows just like a regular table), exceptfor the fact that the real
tables store data, while the views don’t. The view’s data is generateddynamically wh
en the view is referenced. A view references one or more existing databasetables
or other views. In effect every view is a filter of the table data referenced i
n it and thisfilter can restrict both the columns and the rows of the referenced
tables.
Here is an example of how to create a SQL view using already familiar Product an
dManufacturer SQL tables:
CREATE VIEW vwAveragePrice AS
SELECT Manufacturer, ManufacturerWebsite, ManufacturerEmail, AVG(Price) ASAvgPri
ce
FROM Manufacturer JOIN ProductON
Manufacturer.ManufacturerID = Product.ManufacturerID
GROUP BY Manufacturer, ManufacturerWebsite, ManufacturerEmail
A view can be referenced and used from another view, from a SQL query, and from
storedprocedure. You reference a view as you would reference any real SQL databa
se
table:
SELECT * FROM vwAveragePrice.
Both the joins and views have their importance in DBMS and play a important role
inDBMS.

Database practitioners can define views as read-only or updatable. If the databa


se system can determine the reverse mapping from the view schema to the schema o
f the underlying base tables, then the view is updatable. INSERT, UPDATE, and DE
LETE operations can be performed on updatable views. Read-only views do not supp
ort such operations because the DBMS cannot map the changes to the underlying ba
se tables. A view update is done by key preservation.
Some systems support the definition of INSTEAD OF triggers on views. This techni
que allows the definition of other logic for execution in place of an insert, up
date, or delete operation on the views. Thus database systems can implement data
modifications based on read-only views. However, an INSTEAD OF trigger does not
change the read-only or updatable property of the view itself.
nd on it.

Q-5 Course(Course_id, course_name,)


Teacher(Teacher_id,Teacher_name,age,salary)
Assigned_to(Teacher_id,Course_id)
Solve the following SQL Queries:
Ans:-
a) Find out the id’s of Course and names of teachers from Course and teacher.
Ans:-Select * from course, teacher,, course_id,course name,teacher_id;

b) Find the teacher_id of the teacher who are teaching at least 3 courses.
Ans:- Select * from teacher, teacher_id where course=3;
c) Display the names of all those teachers where 2nd alphabet of the name i
s ‘a’.
Ans:-SQL>select ename from Teacher where ename like _a%
d).Count the number of teachers in a university and display them under column ‘Tot
al’
Ans:-Select count( total teacher) from university;

Q-6 Illustrate the use of SET Operations with Select Command .


Ans:- SQL has directly incorporated some set of operations
There is a union operation (UNION), and in some version of SQL there ar
e set of difference (MINUS) and interction(INTERSECT) OPERATION.
The set operation apply only to union compitable relation;the two relation must
have the same attributes and the attributes must appear in the same order.
(SELECT PNAME
FROM PROJECT,DEPARTMENT,EMPLOYEE
WHERE DNUM=DNUMBER AND MGRSSN=SSN
AND LNAME=’smith’
UNION (SELECT PNAME
FROM PROJECT,WORKS_ON,EMPLOYEE
WHERE PNUMBER=PNO AND ESSN=SSN AND LNAME=’smith’)

Thank You,,,,,,,,,,,,

Das könnte Ihnen auch gefallen