Enable and disable materialized views

You can control whether a materialized view is available for use by the database server by enabling or disabling it. A disabled materialized view is also not considered by the optimizer during optimization. If a query explicitly references a disabled materialized view, the query fails and an error is returned. When you disable a materialized view, the database server drops the data for the view, but keeps the definition in the database. When you re-enable a materialized view, it is in an uninitialized state and you must refresh it to populate it with data.

Regular views that are dependent on a materialized view are automatically disabled by the database server if the materialized view is disabled. As a result, once you re-enable a materialized view, you must re-enable all dependent views. For this reason, you may want to determine the list of views dependent on the materialized view before disabling it. You can do this using the sa_dependent_views system procedure. This procedure examines the ISYSDEPENDENCY system table and returns the list of dependent views, if any.

When you disable a materialized view, the data and indexes are dropped, and if the view was an immediate view, it is changed to a manual view. So, when you re-enable it, you must refresh it, rebuild the indexes, and change it back to immediate view (if necessary).

You can grant permissions on disabled objects. Permissions to disabled objects are stored in the database and become effective when the object is enabled.

 To disable a materialized view (Sybase Central)
  1. Use the SQL Anywhere 12 plug-in to connect to the database as a user with DBA authority or as the owner of the materialized view.

  2. In the left pane, double-click Views.

  3. Right-click the materialized view and choose Disable.

 To disable a materialized view (SQL)
  1. Connect to the database as a user with DBA authority, or as owner of the materialized view.

  2. Execute an ALTER MATERIALIZED VIEW ... DISABLE statement.

 To enable a materialized view (Sybase Central)
  1. Use the SQL Anywhere 12 plug-in to connect to the database as a user with DBA authority or as the owner of the materialized view.

  2. In the left pane, double-click Views.

  3. Right-click the materialized view and choose Recompile And Enable.

  4. Optionally, right-click the view and choose Refresh Data to initialize the view and populate it with data.

 To enable a materialized view (SQL)
  1. Connect to the database as a user with DBA authority, or as owner of the materialized view.

  2. Execute an ALTER MATERIALIZED VIEW ... ENABLE statement.

  3. Optionally, execute a REFRESH MATERIALIZED VIEW to initialize the view and populate it with data.

 Example of disabling a materialized view
 Example of enabling a materialized view
 See also