Database Management System Practical No: 9 Aim: I) To Perform Operations On Views
Database Management System Practical No: 9 Aim: I) To Perform Operations On Views
Practical No : 9
view
• Views in SQL are considered as a virtual table. A view also contains rows
and columns.
• To create the view, we can select the fields from one or more tables present
in the database.
• A view can either have specific rows based on certain condition or all the
rows of a table.
Creating View
CREATE or REPLACE VIEW view_name
AS
SELECT column_name(s)
FROM table_name
WHERE condition
AS
The data fetched from SELECT statement will be stored in another object called
emp_view. We can use CREATE and REPLACE separately too, but using both
together works better, as if any view with the specified name exists, this query
will replace it with fresh data.
Update a view
Destroying a view
Read-only view : We can create a view with read-only option to restrict access
to the view.
================================================================
Sequences
A sequence is a set of integers 1, 2, 3, ... that are generated in order on
demand. Sequences are frequently used in databases because many
applications require each row in a table to contain a unique value and
sequences provide an easy way to generate them.
Creating sequences
Referencing a sequence
Altering sequences
Destroying a sequence
Exercise
1. The organization wants to display only the details of the employees those
who are managers [Manager_Record].
2. The organization wants to display only the details like empno, empname,
deptno, deptname of the employees [Employee_Detail].
3. The organization wants to display only the details like
empno,empname,deptno,deptname of the all the employees except the
managers and [NoManager].
4. Display all the views generated.
5. Execute the DML commands on the view created.
6. Find the departments of all mangers from Manager_detail.
7. Find name along with department name from Employee_detail.
8. Find Eno, and their corresponding dname from No_Manager.
9. Add a column Address in Manager_Record.
10. Change a column name Deptno to D_ID in No_Manager.
11. Change size of Empname column to 20 in Employee_Detail
12. Drop a view.
13. Create a sequence to insert the data in table person(pid, name, age), which
automatically takes the value of pid, which starts with 101 and
incremented by 1, and the valid range for pid is 101-199.
14. Update the sequence created in the above question and increment the
value with 2.
15. What is view?
16. What is Indexed view? How to create it?
17. What are partitioned views and distributed partitioned views?
18. What functions can a view be used to performed?
19. Describe the functionalities that views support.
20. What are the restrictions that views have to follow?
21. Explain the use of cache option in creation of a sequence.