Simple Database Views (update, insert, delete)

335 Views Asked by At

In my university notes I am currently attempting to study views but nowhere in the material is the criteria that shows when a simple view can be updated, inserted or deleted. I assume privileges can have a lot to do with this and seems like common sense to not allow data in a view to be deleted by anyone other than the person who created the view but this isn't about common sense just is it possible to update, insert or delete a view and what is the criteria of that.

for my example I have created a view called EmployeeNames which takes the first_name, last_name under a new field Names like so

CREATE VIEW EmployeeName as  
SELECT first_name + last_name "Names"
FROM Employees; 

(not altogether sure of this syntax either but i think its right)

can this field be updated, inserted or deleted by anyone who has access to this view?(without privileges)

2

There are 2 best solutions below

3
On

There are certain conditions must be met, so that view could be updatable. If you have, for example, an aggregate functions in view, you obviously cannot update it.

For Oracle more information you could find here

For MySQL it's pretty similar to oracle

0
On

In SQL server there are specific rules for updating views and they are very complicated. Each DB would do this differently. Probably the majority of views I have seen over the years are unupdateable due to these rules.

Personally, I prefer to update tables directly and not through views. If you may have differnt database backends, tehyn I would defintely consider direct updating of tables instead as the rules are very differntfor each datbase.