Creating view: – A view table is used to avoid redundancy or repetition of data. It is used for multiple table. If user want to insert data in multiple table using single insert statement, view table provide this facility. The view table is useful only when number of tables are existed for creating view. Sometimes writing a query own different relation or tables becomes more complex then writing a query on a single table. So, views are used to give simplified representation. Syntax for creating view table is –

                Create view <View Table Name> as select <Expression>;

Some example of view table –

Suppose we have a table named employee. This table contains number of columns such as ename, ecode, city, location, salary, jdate and show on. Out of multiple column, if we want to insert data in only ename and salary column, we create a view table flowed by insert data only in selected table but it automatically transferred actual table. For example –

                Create view v1 as select ename,salary from employee;

Now a view table v1 is created we insert data in view table but it transfers in old table.

                Insert into v1 values (‘Ashok’,1200);

Here, we insert data in table v1 but it is actually transfer to employee table.

Suppose we have two tables namely employee and company. There are number of columns in both tables but we want to insert data in ename column and salary column of table employee and city column and jdate column of table company, we create a view table in the following formate.

                Create view v1 as select employee.ename,employee.salary,company.city,company.jdate from employee,company;

Now we insert data in view table but it actually transferred to both tables employee and company of selected column only.

Advertisements