In SQL, is there any advantage to using multiple views rather than a single view?

Currently, I want to replace an existing stored procedure and am wondering if there is any benefit in creating multiple views where the selection should join different views, and not to one view in which the selection does not have any connections.

+4
source share
4 answers

I have two points of view for this

  • Suppose your application has something reusable that is already written in a stored process and can be reused in another stored procedure. Thus, you can transfer this part to the view and call the view both in stored procedures, and in the future you can filter to the desired result.

  • Unnecessary use of views can cause performance problems. Since the views do not accept input parameters, so it will select all the relevant rows depending on your Inner / Left connection

+1
source

The only advantage I could imagine would be if different views had independent significance. In other words, can they be useful elsewhere on their own? If not, just create one view.

+1
source

If you do not add indexes to the view (thus materializing it), it does not really matter, since the query analyzer will treat them the same way. Therefore, you should use whatever is best for your particular application (even if it is only in terms of support or readability).

+1
source

Several views will allow you to be more detailed when you choose who can see that (if you use the views for security purposes). Basically you can say that group A can only see data in View A, group B can only see data in view B, etc.

If you use indexed views to improve performance, I would stick with one view that brings you together. Since this data will be saved, this can save you the cost of completing the connection.

+1
source

Source: https://habr.com/ru/post/1393055/


All Articles