Beruflich Dokumente
Kultur Dokumente
*********-----------***********----------*********------------******
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.
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;
Thank You,,,,,,,,,,,,