0% found this document useful (0 votes)
54 views3 pages

Views

1) Views are logical tables that do not take up storage space and instead store only the query definition in the data dictionary. 2) Views can be used to reduce complexity, improve security by restricting access to columns, and rename table columns. 3) The CREATE VIEW statement is used to define a view based on a query, and views can then be updated, inserted into, or have data inserted using the "OR REPLACE" option which will replace an existing view definition.

Uploaded by

pandsin
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views3 pages

Views

1) Views are logical tables that do not take up storage space and instead store only the query definition in the data dictionary. 2) Views can be used to reduce complexity, improve security by restricting access to columns, and rename table columns. 3) The CREATE VIEW statement is used to define a view based on a query, and views can then be updated, inserted into, or have data inserted using the "OR REPLACE" option which will replace an existing view definition.

Uploaded by

pandsin
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Views

Definition: Views are known as Logical (or) Base tables. Creating a views does not take any storage space as only the query is stored in data dictionary and the actual data is not stored any where Benefits/Advantages of SQL Views: The reasons for using views in application can be many like Reducing complexity Improving security Renaming the table columns.

Syntax: CREATE [OR REPLACE] [FORCE] VIEW view name [(column-name, column-name)] AS Query [with check option]; Creating SQL VIEW Use create view statement to create a view: SQL> conn Scott/tiger; Connected. SQL>select * from tab; //it displays the Scott user of all tables and views; EMP DEPT SALGRADE BONUS SQL>desc EMP; //describe the structure of the EMP table; Name EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO SQL> desc dept; Null? Type

NOT NULL NUMBER (4) VARCHAR2 (10) VARCHAR2 (9) NUMBER (4) DATE NUMBER (7, 2) NUMBER (7, 2) NUMBER (2)

Views
Name DEPTNO DNAME LOC Null? Type NOT NULL NUMBER(2) VARCHAR2(14) VARCHAR2(13)

SQL> select ename, empno,sal,job from emp where deptno=20; ENAME SMITH JONES SCOTT ADA FORD 7369 7566 7788 7876 7902 EMPNO SAL 800 2975 3000 1100 3000 JOB CLERK MANAGER ANALYST CLERK ANALYST

SQL> create view emp_view 2 as 3 select ename,empno,sal,job from emp 4 where deptno=20; View created. SQL> select * from emp_view; ENAME SMITH JONES SCOTT ADAMS FORD EMPNO 7369 7566 7788 7876 7902 SAL 800 2975 3000 1100 3000 JOB CLERK MANAGER ANALYST CLERK ANALYST

INSERT, UPDATE and INSERT on Views: For insert data in views use the OR REPLACE option. If the view exists it will be replaced with new definition or a new view will created. We can use create or replace option to create view instead of dropping the view and recreating it, as with this option the privileges granted on the view are preserved, but the dependent stored programs and view become invalid. Whereas FORCE option is force to create a view even if the base table does nt exist. Any way the base table should exist before the view is used.

Views

You might also like