Can you update a view in a database? If so, how? If not, why not?
SQL Updating a ViewA view can be updated with the CREATE OR REPLACE VIEW statement.
Yes, possible to insert,update and delete to view. view is a virtual table. Same Perform as insert,update,delete query.. A view can be defined as a virtual table or a stored query and the data accessible through a view is not stored in the database as a distinct object.
It means that the server always knows whether a view is updatable. If a view is not updatable, statements such UPDATE , DELETE , and INSERT are illegal and are rejected. (Even if a view is updatable, it might not be possible to insert into it, as described elsewhere in this section.)
Yes, they are updated, every time you use them.
The actual answer is "it depends", there are no absolutes.
The basic criteria is it has to be an updateable view in the opinion of the database engine, that is to say can the engine uniquely identify the row(s) to be updated and secondly are the fields updateable. If your view has a calculated field or represents the product of a parent/child join then the default answer is probably no.
However its also possible to cheat... in MS SQL Server and Oracle (to take just two examples) you can have triggers that fire when you attempt to insert or update a view such that you can make something that the server doesn't think updateable into something that is - usually because you have knowledge that the server can't easily infer from the schema.
The correct answer is "it depends". You can't update an aggregate column in a view for example. For Oracle views you can Google for "updatable join view" for some examples of when you can and cannot update a view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With