有时我发现一些代码可以触发允许用户从 View 中删除? 但是为什么我们需要从 View 中删除,因为我们可以像下面这样简单的代码一样转到 Table > 并执行删除:
delete from table where x=y ;
我的问题是为什么我们要使用 TRIGGERS 来删除 View ? 换句话说,使用删除相对于 View 有什么优势!
最佳答案
The reason we use view are mainly to hide the complexity of data sources , Hide away the actual tables (For security reasons), saving us writing the same code over and over again.
Now if you havent let your users access the tables directly and they only work through View in this case they will be executing
Deletes
against views.Triggers are only used when your View has more than One underlying table. You cannot do update, insert or delete operations on view if it effects multiple underlying tables. Therefore we make use of
Instead of Delete/Update/Insert Triggers
to do these operations against views.When you have multiple Underlying tables if you Update,Delete or Insert effects only One underlying table it does allow you to execute the statement but it is not guaranteed that it will be done correctly.
therefore if you have a situation where your view is based on multiple underlying tables you should always do update/delete/inserts
1) Directly to underlying tables.
2) Use Instead of triggers.
还有 Read here 了解有关为什么不应对具有多个基础表的 View 执行更新/删除/插入操作的更多详细信息。
关于sql - 为什么我们需要触发器来从 View 中删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21591020/