ALTER VIEW statement applies a schema change to a view.
The
ALTER VIEW statement performs a schema change. For more information about how online schema changes work in CockroachDB, see Online Schema Changes.Required privileges
- To set or reset
security_invoker, the user must own the view. - To change the schema of a view with
ALTER VIEW ... SET SCHEMA, the user must have theDROPprivilege on the view and theCREATEprivilege on the new schema. - New in v26.3: To rename a view with
ALTER VIEW ... RENAME TO, the user must have theDROPprivilege on the view and theCREATEprivilege on the view’s schema.
Syntax
Parameters
Known limitations
ALTER VIEW does not currently support:
- Changing the
SELECTstatement executed by a view. Instead, you must drop the existing view and create a new view. - Renaming a view that other views depend on. This feature may be added in the future.
Examples
Rename a view
Suppose you create a new view that you want to rename:RENAME TO only changes the name of the view; it cannot move the view to a different database or schema. To change a view’s schema, use the SET SCHEMA clause.
Change the schema of a view
Suppose you want to add theexpensive_rides view to a schema called cockroach_labs:
By default, unqualified views created in the database belong to the public schema:
Set or reset security_invoker
By default, a view checks privileges on the underlying tables as the view owner. To change the view to use the querying user’s privileges instead, include the security_invoker option:

