110 likes | 282 Views
Views. Views. Logical data is how we want to see the current data in our database . Physical data is how this data is actually placed in our database. Views may be created for the following reasons :-. Provides data security Simplifies queries Can be queried as a table itself .
E N D
Views • Logical data is how we want to see the current data in our database. • Physical data is how this data is actually placed in our database.
Views may be created for the following reasons :- • Provides data security • Simplifies queries • Can be queried as a table itself. • Avoids data redundancy. • Prevents updating a record as DBA knows you are really working with a subset of a record.
Creation of views Syntax Create view <Viewname> as Select <columnname1>, <columnname2> ……. from <tablename> where <column name> = <expression liat>; Example SQL> Create view emp_view as select eno, ename, salary from emp where salary>=5000;
Rename the columns of a view SQL> create view emp_view as select eno,ename,salary, dno from emp where eno between 10 and 100; (give existing view name )
Update table join views SQL> Create view ex_v1 as select emp.eno, emp.ename, emp.dno, dept.dname from emp,dept where dept.dno=emp.dno;
Destroying a view Syntax Drop view <viewname> Example SQL> drop view emp_xx;
Example SQL>create view v1 as select * from emp; SQL>create view v1 (emp_name,salary) as select ename, salary from emp; SQL> Select * from user_views;
Check option • Std Rollno Name create table Sub1 Sub2 Sub3 SQL> Create view std_best as select rollno,name,sub1,sub2,sub3 from std where sub3>=90 with check option;
Update option SQL> Create view v2 (eno,ename,salry) as select eno,ename, salary*2 from emp; SQL> select * from v2; SQL>create view v3 (deptno, salary) as select dno,sum(salary) from emp group by dno;
SQL> Create view h1 as select ename, salary from emp where salary>=5000 with check option; SQL> insert into h1 values (‘ram’,7000); SQL> insert into h1 values (‘ravi’,3000); (Not insert )