Unit 4 - DBMS POD Board Question Answer
Unit 4 - DBMS POD Board Question Answer
OUR SERVICES:
Diploma in All Branches, All Subjects
Degree in All Branches, All Subjects
BSCIT / CS
Professional Courses
2017
2016
Q. What is view? Definition of view: 2 marks)
Ans :
View: A view is a logical extract of a physical relation i.e. it is derived from any
base
relation.
OR
View: Views are virtual relations mainly used for security purpose, and can be
provided
on request by a particular user.
Create view EMPVIEW as select empname, empid, dob, salary, job from
employee where salary>20000;
OR
CREATE VIEW EMPVIEW AS SELECT * FROM EMPLOYEE WHERE
SALARY >20000;
Q. What are views? Give its syntax and explain its advantages.
(Views - 2 marks; Syntax - 1 mark; Advantages (Any two) - 1 mark)
Views are created for security reasons. Instead of coping same table multiple times
for different requirements, views can be created. View is a logical copy of physical
table.
It doesn‘t exist physically. With the help of view, we can give restricted access to
users. When view is used, underlying table is invisible, thus increasing security.
Views can be used to see, insert, update and delete data from base table.
Advantages of Views:
Views restrict access to the data because the view can display selective
columns from the table.
Views can be used to make simple queries to retrieve the results of
complicated queries. For example, views can be used to query information
from multiple tables without the user knowing how to write a join statement.
Views provide data independence for adhoc users and application programs.
One view can be used to retrieve data from several tables.
Views provide groups of users to access to data according to their particular
criteria. Thus implements security and authorization.
2015
As subquery
Example :
Create view emp_info as select Emp_no, Emp_name from Employee where
salary>12000;
To describe content of view
Select * from emp_info;
To describe structure of view
describe emp_info;
Ans: Syntax for creating view. Create view <viewname> as select <query>
2016
Q. What are sequence? Why it is used? Create sequence for STUDENT table.
(Definition - 1 mark; Use - 1 mark; creating valid sequence example/pattern - 2
marks)
Ans:
Definition: A sequence refers to a database object that is capable of generating
unique and sequential integer values.
Use:
1. It saves a time by reducing application code.
2. It is used to generate unique sequential integers.
3. It is used to create an auto number fields.
4. Sequence can be use for many tables/relations
Sequence for ‘student’ table: Create sequence student_seq increment by 1 start
with 1 maxvalue 60 nocycle;
2015
Where,
Example:
Create sequence student_seq increment by 1 start with 1 maxvalue 60 nocycle;
4) Dropping a Sequence
The DROP SEQUENCE command is used to remove the sequence from database.
Syntax:
DROP SEQUENCE<SequenceName>;
2014
Syntax:
2016
Example:
CREATE INDEX ename_idx on emp (ename);
b) Composite Index:
A composite index is an index created on two or more columns of a table.
The basic syntax is as follows:
CREATE INDEX index_name on table_name (column1, column2);
Example:
CREATE INDEX en_idx
on emp (ename,job);
c) Unique Indexes:
Unique indexes are used not only for performance, but also for data integrity. A
unique index does not allow any duplicate values to be inserted into the table. The
basic syntax is as follows:
2015
Q. Explain the concept of indexing with neat diagram.
(Explanation - 3 Marks, Any relevant Diagram - 1 Mark)
Ans:
Index: An index is a schema object that can speed up the retrieval of rows by
using pointer. An index provides direct and fast access to rows in a table. Indexes
are created explicitly Or automatically. Indexes are used to speed up
searches/queries.
Types of Index:
Simple index(Single column): An index created on single column of a table is
called a Simple Index.
Unique indexes are used not only for performance, but also for data integrity. A
unique index does not allow any duplicate values to be inserted into the table.
Composite (concatenated): Indexes that contain two or more columns from the
same table which are useful for enforcing uniqueness in a table column where
there’s no single column that can uniquely identify a row.
2014
2017
Q. Explain snapshot with example. (4 Marks)
Snapshot:
It is also known as materialized view.
It is a copy of either an entire single table or set of its rows or collection of
tables, views or rows using join, grouping and
selection criteria.
Useful in distributed environment
It has two types:
Simple snapshot and complex snapshot. Simple snapshot related to single table and
complex snapshot related to joined tables.
Example :
Operations on snapshot:
i) Creating Snapshot:
Create snapshot command is used to create the snapshot.
Syntax:-
CREATE SNAPSHOT [schema.] <snapshot name>AS subquery;
Example:-
Create snapshot emp_snapas select * from emp where deptno=6;
ii) Altering snapshot:
Snapshot can be altered by using ALTER SNAPSHOT command.
The only parts ofa snapshot that can be altered are its storage parameters,
refresh type and refresh start,and next interval.
The select for the snapshot, base tables, and other data related items cannot
be changed without dropping and recreating the snapshot.
Syntax:-
ALTER SNAPSHOT <snapshotname>
[[PCTFREE <integer>]
[PCTUSED <integer>]
[REFRESH [FAST/COMPLETE/FORCE]];
Example:-
To change the automatic refresh mode for the emp_data snapshot to
fast:
ALTER SNAPSHOT emp_data REFRESH FAST;
iii) Dropping a snapshot
To remove the snapshot DROP SNAPSHOT Command .When
snapshot is dropped which a snapshot log had associated with it, only
the rows required for maintainingthat snapshot are dropped.
Syntax:-
Drop snapshot <snapshot name>;
Example:-
Drop snapshot emp_snap;
2016
Uses:
Useful in distributed environment.
Response time of the queries gets minimized as the client has made a local
copy of master table.
If the master table gets corrupted, then data can be restored using snapshot.
Creating Snapshots:
Create snapshot command is used to create the snapshot.
Syntax:
Create snapshot snapshot_name refresh with rowid as <select query>;
Example:
Create snapshot emp_snap refresh with rowid as select * from emp;
i) Creating Snapshot:
Create snapshot command is used to create the snapshot.
Syntax:-
CREATE SNAPSHOT [schema.] <snapshot name>
AS subquery;
Example:-
Create snapshot emp_snap
as select * from emp where deptno=6;
Example:-
To change the automatic refresh mode for the emp_data snapshot to fast:
ALTERSNAPSHOT emp_data REFRESH FAST;
2014
Q. What is snapshot? Write the syntax for creating a snapshot. (Explanation-
2 Marks, Syntax- 2 Marks)
Ans:
Snapshot:
It is also known as materialized view.
It has two types: Simple snapshot and complex snapshot. Simple snapshot related
to single table and complex snapshot related to joined tables.
Syntax:
Create snapshot snapshot_name Pctfree n Pctused n Tablespace tablespace_name
Storage clause Refresh Star with date As select statement;
OR
Create snapshot snapshot_name As select statement;
2014
Q What are synonyms? Write a syntax for creating a synonym. (Synonym
definition -2 Marks, Correct syntax -2 Marks)
Ans:
A synonym is an alternative name for objects such as tables, views,
sequences, stored procedures, and other database objects.
You generally use synonyms when you are granting access to an object from
another schema and you don't want the users to have to worry about
knowing which schema owns the object.
Syntax:
CREATE [OR REPLACE] [PUBLIC] SYNONYM [schema.] synonym_name
FOR [schema.] object_name;
OR
create synonym synonym_name for object_name;
DROP SYNONYM
Once a synonym has been created in Oracle, you might at some point need to drop
the synonym.
Syntax
The syntax to drop a synonym in Oracle is:
DROP [PUBLIC] SYNONYM [schema .] synonym_name [force];
PUBLIC
Allows you to drop a public synonym. If you have specified PUBLIC, then you
don't specify a schema.
force
It will force Oracle to drop the synonym even if it has dependencies. It is probably
not a good idea to use force as it can cause invalidation of Oracle objects.
Example
Let's look at an example of how to drop a synonym in Oracle.
For example:
DROP PUBLIC SYNONYM suppliers;
This DROP statement would drop the synonym called suppliers that we defined
earlier.