Performance of data retrieval process from SQL views

201 views Asked by At

SQL documentation states that

The database engine recreates the data, using the view's SQL statement, every time a user queries a view

How does data retrieval process from SQL views offers better performance as compared to execution of select query to retrieve data from tables.

2

There are 2 answers

0
Queen On

Basically Views are Used for Security purpose Than for performance,while Using Views you can restrict the users from Accessing a particular Table.

The only difference is Views can be saved and reused whenever required,than to rewrite the whole Query again.

0
David דודו Markovitz On

Views are just queries with names.
It is like saving a code snippet (in the database level) so you won't have to write the same code again and again.
Views have nothing to do with performance.

Being that said -
There is a mechanism named "Materialized views", where in this case the query result is actually stored in a table so it can be used without executing the query again and again.
The Materialized views results might be refreshed in multiple manners -
on demand, on schedule, every time the base table is being updated etc.