Reputation: 509
I am developing an application and I have a very complex query, to simplify the querying process I decided to use an sql view, to store the query data so that I can easily query the complex query's data from the view. The function works and it displays the data that I want. What I really like to do is, is it the best practice to use views instead of tables to query information from the database. Thanks
Upvotes: 0
Views: 941
Reputation: 1
Using regular views offloads the database query writing and optimization onto the potentially more experience DBA responsible for the core database itself.
Using a view effectively migrates the business logic of a query into the database layer where the rules can be centrally inforced independent of any one application. The DBA can optimize a view for performance or data integrity reasons without forcing a refactoring of the application as long as the view continues to meet the same result set.
Having a view allows a DBA to review and optimize where feasible. Also if not using views the long query will have to be sent and parsed each time your request data. A view is quasi pre-parsed on creation of the view and will save that time.
Upvotes: 0
Reputation: 2489
In specific use cases views are a perfectly acceptable way to simplify application logic by encapsulating complex queries within the database. I see nothing wrong with what you have described.
Upvotes: 3