Is it possible to update Views? If yes, How, If Not, Why?

Questions by nagurtilak

Showing Answers 1 - 75 of 81 Answers

Shikhar

  • Dec 13th, 2006
 

You cannot update a view by writting a insert, update or delete query on the view. If you want to update some data in the view than you have to update the underlying tables.

  Was this answer useful?  Yes

Dev

  • Dec 19th, 2006
 

Hi Shikar,

You are wrong. We can update a view by using insert,update,delete statements.

A view from a single table can be updated where as a view from multiple tables can not be updated.

Thanks

Dev.

ramesh t

  • Dec 21st, 2006
 

the meaning of view is snapshot of the table .

 without disturbing the main table we done in view so we can perform the dml commnads in it.

 i think u understood

  Was this answer useful?  Yes

srikanth

  • Dec 29th, 2006
 

view is collection of data but itis not stored in database.To simplfy the selected statements we can use view and itis snapshot for table

we can update view by using DML commands

  Was this answer useful?  Yes

rajesh

  • Jan 3rd, 2007
 

If u have Created a View.. based on 2 Tables... u can use dml statements on that view.. but u can perform DML Operations Only on Key Preserved Table.

Shailendra Nigam

  • Jan 4th, 2007
 

Hi

I am shailendra

its my op.

yes

you can update the view

suppose you can create the view

create view v1 as select ename,sal from emp

suppose you want to update the view according to salary

update v1 set ename='shailendra' where sal=800;

rahul Omanwar

  • Jan 5th, 2007
 

Hello Shailendra,

 This is rahul.As per discussion on views. I want to share some thing. There are two types of views namely Simple and complex views.

U can perform DML operation on simple views which is based on single table and that view doesn't contain any single row function and any group by clause and it has to satiesfy integrity constraint also.

U can't perform DML operation on complex views becuase they are based on multiple table. U can achive this task by using Triggers(Instade of...).

If u have any suggestion on bellow discussion please send mail to rahul_omanwar@hotmail.com.

Thanks and regards,

Rahul Omanwar

mob no : 9423612912

srinivasaraok

  • Feb 7th, 2007
 

Hi

Suppose you want update view means that time you need to use insted of trigger with that only possible to update view



Srinivas

  Was this answer useful?  Yes

Gman

  • Feb 22nd, 2007
 

A materialized view can be updated.

  Was this answer useful?  Yes

sreenivas

  • Mar 13th, 2007
 

Hai I am sreenivas kumar from Andhra Pradesh.
      Yes, it is possible to update the vies created on single table,if the vies are created on multiple tables then it is not possible to update ,if we want to update these type of vies then we have to create an instead of trigger ,then only we can update the views created on multiple tables.

  Was this answer useful?  Yes

pairohit123

  • Apr 22nd, 2009
 

A join view is defined as a view that has more than one table or view in its FROM clause (a join) and that does not use any of these clauses: DISTINCT,
AGGREGATION, GROUP BY, START WITH, CONNECT BY, ROWNUM, and set operations (UNION ALL, INTERSECT, and so on).

An updatable join view is a join view that involves two or more base tables or views, where UPDATE, INSERT, and DELETE operations are permitted. In order to be inherently updatable, a view cannot contain any of the following constructs:

1 A set operator
2 A DISTINCT operator
3 An aggregate or analytic function
4 A GROUP BY, ORDER BY, CONNECT BY, or START WITH clause
5 A collection expression in a SELECT list
6 A subquery in a SELECT list
7 Joins (with some exceptions).

The data dictionary views ALL_UPDATABLE_COLUMNS, DBA_UPDATABLE_COLUMNS, and USER_UPDATABLE_COLUMNS contain information that indicates which of the view columns are updatable.   Views that are not updatable can be modified using INSTEAD OF triggers.

  Was this answer useful?  Yes

gourav

  • Aug 19th, 2011
 

a view from more than 1 table can also b updated if it has primary key...

  Was this answer useful?  Yes

sohani

  • Aug 20th, 2011
 

Http://psoug.org/reference/instead_of_trigger.html
http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_8004.htm

example :

Code
  1. CREATE TABLE family_details

  2. ( NAME VARCHAR(25),

  3. AGE NUMBER,

  4. SEX CHAR,

  5. STATUS VARCHAR2(8),

  6. PRIMARY KEY (REL_ID));  

  7.  

  8. CREATE TABLE relation_type

  9. ( rel_id NUMBER NOT NULL,

  10. relation_type VARCHAR2(30),

  11.  foreign KEY (rel_id) references sohani(REL_ID)

  12. );  

  13.  

  14. CREATE VIEW family_view

  15. AS

  16. SELECT s.rel_id prim_id ,name,sex,age,status,relation_type ,r.rel_id sec_id FROM family_details s, relation_type r

  17. WHERE r.rel_id = s.REL_ID

  18.  

  19.  

  20. WILL PASS :INSERT INTO family_view (prim_id,name ,sex, age,status) VALUES (7,'mmm','F',34,'married')

  21. ( make sure ALL NOT nullable columns are included )

  22. WILL PASS : INSERT INTO family_view (sec_id,RELATION_TYPE) VALUES (7,'granny')

  23.  

  24. WILL FAIL : INSERT INTO family_view (prim_id,name ,sex, age,status,relation_type,sec_id) VALUES (6,'kishan','M',32,'single','brother',6);

  25.  


same case with update

  Was this answer useful?  Yes

Hello,
Yes, you can modify views based on a single table or on a join on many tables but...:

A DML statement on a join view can modify only one base table of the view (so even if the view is created upon a join of many tables, only one table, the key preserved table can be modified through the view).
To be modifiable, a join view must also preserve a key from at least one of its tables.

For example, we create a view based on a join on two tables employee and retailer:

desc employee:
emp_id numeber4)
name varchar2(50)
salary number(9)

desc retailer
rtlr_nbr number(5)
name varchar2(50)
address varchar2(50)
salesperson_id number(4)

our view looks like this:

CREATE OR REPLACE VIEW v_rtlr_emp AS
SELECT c.rtlr_nbr, c.name, e.emp_id,
c.salesperson_id, e.name sales_rep
FROM retailer c JOIN employee e
ON c.salesperson_id = e.emp_id;

And let's say that the result is:
RTLR_NBR / NAME / EMP_ID / SALES_REP

104 / EVERY MOUNTAIN / 7499 / ALLEN
107 / WOMENS SPORTS / 7499 / ALLEN
201 / STADIUM SPORTS / 8421 / MICHAELS
300/ REBOUND SPORTS / 9122/ JOHNATAH

The primary key of the retailer is rtlr_nbr, as well as the key for the result of our join.

So only the retailer table can be modified through the v_rtlr_emp view.

Have a good day

  Was this answer useful?  Yes

Satyendra Kumar

  • Oct 11th, 2011
 

Hi Shekhar,

As per my understanding we can update or insert or delete data from view but it will reflect to the underlying table too.

Satyendra

  Was this answer useful?  Yes

SIVA KARTHIK

  • Dec 11th, 2011
 

Code
  1. SQL> CREATE VIEW VIEW1 AS SELECT ENAME,SAL FROM EMP;

  2.  

  3. VIEW created.

  4.  

  5. SQL> SELECT * FROM VIEW1;

  6.  

  7. ENAME             SAL

  8. ---------- ----------

  9. SMITH             531

  10. ALLEN           20644

  11. KING             3317

  12. JONES            1974

  13. BLAKE           36775

  14. CLARK            1625

  15. TURNER          19353

  16. ADAMS             730

  17. JAMES           12259

  18. MILLER            862

  19. WARD            16128

  20.  

  21. ENAME             SAL

  22. ---------- ----------

  23. FORD             1991

  24. SCOTT            1991

  25. MARTIN          16128

  26.  

  27. 14 rows selected.

  28.  

  29. SQL> UPDATE VIEW1 SET ENAME=HHH WHERE ENAME=SMITH;

  30.  

  31. 1 row updated.

  32.  

  33. SQL> SELECT * FROM VIEW1;

  34.  

  35. ENAME             SAL

  36. ---------- ----------

  37. HHH               531

  38. ALLEN           20644

  39. KING             3317

  40. JONES            1974

  41. BLAKE           36775

  42. CLARK            1625

  43. TURNER          19353

  44. ADAMS             730

  45. JAMES           12259

  46. MILLER            862

  47. WARD            16128

  48.  

  49. ENAME             SAL

  50. ---------- ----------

  51. FORD             1991

  52. SCOTT            1991

  53. MARTIN          16128

  54.  

  55. 14 rows selected.

  Was this answer useful?  Yes

ajay goel

  • Jun 23rd, 2014
 

We cant execute DML on complex views but can execute on simple views ..however exceptions are always there. also sometimes we cant even update simple views like if we are updating a row and constraint is that there should not be a null value on the corresponding table. then we will also not be able to update views also so it is uncertain and depends on the situation


  Was this answer useful?  Yes

moshe

  • Mar 11th, 2016
 

No we cant use update statements on view because it is just select statement.

  Was this answer useful?  Yes

View is log table with is having structure of "SELECT STMT DATA"
So view divided into 2 type:
a) Simple
b) Complex

In Simple you can add one table with N number of column

In Complex you have multiple table with different combination of N number of Column

Only in Simple you can update the view in complex is not possible.

  Was this answer useful?  Yes

shafiq

  • May 17th, 2016
 

You can update tables through their views by simple update statement.

  Was this answer useful?  Yes

Muraleedhar Reddy B

  • May 21st, 2016
 

We can perform DML on the view when
1.View is built based on a single table
2.Primary key of the table should be availbale in select clause used for view
We can not perform DML on the view when
1. View is bulit on multiple tables
However we can use trigger for DML operations on multi table view

  Was this answer useful?  Yes

mayur

  • Jun 12th, 2017
 

Can we insert the value ino table by view when there is order by clause use in the view

  Was this answer useful?  Yes

Vikash

  • Jul 12th, 2017
 

Yes, By instead of update trigger we can update view

  Was this answer useful?  Yes

Sushil Tembhekar

  • Dec 16th, 2017
 

In SQL it is impossible to update the View.
but, By using "Instead of Trigger" clause in PL/ SQL, it is possible to update the View.

  Was this answer useful?  Yes

Asish

  • Jan 7th, 2018
 

Yes, if the view is derived from one base table. Here you can execute all the DML opperation.
No, if the view derived from multiple base table.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions