Computer >> Computer tutorials >  >> Programming >> MySQL

Difference between Views and Materialized Views in SQL


As we know that main constituent of any database is its table, in order to make data accessibility custom there is concept of Views in other words we can say that with the help of Views of a table we can restrict any user to access only that data which is supposed to be accessed by him. Now on the basis of characteristic and features of the views we can distinguish between Views and Materialized Views.

Following are the important differences between Views and Materialized Views.

Sr. No.KeyViewsMaterialized Views
1DefinitionTechnically View of a table is a logical virtual copy of the table created by “select query” but the result is not stored anywhere in the disk and every time we need to fire the query when we need data, so always we get updated or latest data from original tables.On other hand Materialized views are also the logical virtual copy of data-driven by the select query but the result of the query will get stored in the table or disk.
2StorageIn Views the resulting tuples of the query expression is not get storing on the disk only the query expression is stored on the disk.On other hand in case of Materialized views both query expression and resulting tuples of the query get stored on the disk.
3Query ExecutionAs mentioned above in case of Views the query expression is stored on the disk and not its result so query expression get executed every time when user try to fetch data from it so that user will get the latest updated value every time.While on other hand in case of Materialized Views the result of query is get stored on the disk and hence the query expression did not get executed every time when user try to fetch the data so that user will not get the latest updated value if it get changed in database.
4Cost EffectiveAs Views does not have any storage cost associated with it so they also does not have any update cost associated with it.On other hand Materialized Views does have a storage cost associated with it so also have update cost associated with it.
5DesignViews in SQL are designed with a fixed architecture approach due to which there is an SQL standard of defining a view.On other hand in case of Materialized Views in SQL are designed with a generic architecture approach so there is no SQL standard for defining it,and its functionality is provided by some databases systems as an extension.
6UsageViews are generally used when data is to be accessed infrequently and data in table get updated on frequent basis.On other hand Materialized Views are used when data is to be accessed frequently and data in table not get updated on frequent basis.