Alter View
Usage
ALTER [PRIVATE] VIEW <schema_name>.<viewname>[column_name column_type, ..., PRIMARY KEY(column_name), FOREIGN KEY(column_name) REFERENCES another view(column name) ] AS queryExpression;;
Syntax Rules
The
ALTER
query expression may be prefixed with a cache hint for materialized view definitions. The hint will take effect the next time the materialized view table is loaded;PRIMARY KEY
, which uniquely identifies each record in a table, must contain a unique value and cannot be null;FOREIGN KEY
, which refers to the primary key of another view;The number of columns in
queryExpression
must not be changed.
The PRIVATE
keyword is reserved for internal use and should not be specified for user-defined views.
Example
CREATE VIEW views.creditcard AS SELECT * FROM adventureworks.creditcard;
ALTER VIEW views.creditcard AS SELECT * from (SELECT * FROM adventureworks.creditcard) a;
ALTER VIEW views.creditcard(a integer, b integer, PRIMARY KEY(a)) AS SELECT * FROM adventureworks.creditcard;
ALTER VIEW views.userOrder(userId INTEGER, userName INTEGER, orderId INTEGER, FOREIGN KEY(orderId) REFERENCES views.orders(orderId)) AS
SELECT u.userId, u.userName, o.orderId
FROM views.users u
JOIN views.orders o ON u.userId = o.userId;;