When to use database views and when not?

后端 未结 8 968
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 19:31

This question is about database views, not materialized-views.

Pros:

  • Query simplification.
  • Avoid repeat the same joins on mul
相关标签:
8条回答
  • 2020-12-13 19:58

    Pros: Allows you to change the underlying data structures without affecting the queries applications are using (as long as your view can hide the data structures)

    0 讨论(0)
  • 2020-12-13 20:07

    Although views can hide complexity and multiple joins, these is complexity that would have been in the SP anyway.

    If the SP could have been optimized, then the view should be optimized, which would lead to increased performance on all SPs that hit that view.

    Views are incredibly powerful and useful for one reason that stands out above all the other very good reasons. They reduce code duplication. That is, in most cases, the bottom line. If a query will be used in three or more places, then a view will drastically simplify your changes if the schema or query parameters change.

    I once had to edit 22 stored procedures to change some query logic. If the original architecture had utilized views, then I would have had only three changes.

    0 讨论(0)
提交回复
热议问题