Nota
O acesso a esta página requer autorização. Pode tentar iniciar sessão ou alterar os diretórios.
O acesso a esta página requer autorização. Pode tentar alterar os diretórios.
Aplica-se a:
Databricks SQL
Databricks Runtime
Altera os metadados associados à exibição. Ele pode alterar a definição do modo de exibição, alterar o nome de um modo de exibição para um nome diferente, definir e desdefinir os metadados do modo de exibição definindo TBLPROPERTIES.
Para adicionar ou alterar um comentário numa vista, use COMMENT ON.
Se o modo de exibição estiver armazenado em cache, o comando limpará os dados armazenados em cache do modo de exibição e todos os seus dependentes que se referem a ele. O cache da exibição será preenchido preguiçosamente quando a exibição for acessada na próxima vez. O comando deixa os dependentes da exibição como não armazenados em cache.
Sintaxe
ALTER VIEW view_name
{ rename |
SET TBLPROPERTIES clause |
UNSET TBLPROPERTIES clause |
alter_body |
schema_binding |
owner_to |
SET TAGS clause |
UNSET TAGS clause }
rename
RENAME TO to_view_name
alter_body
AS { query | yaml_definition }
yaml_definition
$$
yaml_string
$$
schema_binding
WITH SCHEMA { BINDING | [ TYPE ] EVOLUTION | COMPENSATION }
property_key
{ idenitifier [. ...] | string_literal }
owner_to
[ SET ] OWNER TO principal
Parâmetros
-
Identifica a exibição a ser alterada. Se o modo de exibição não puder ser encontrado, o Azure Databricks gerará um erro TABLE_OR_VIEW_NOT_FOUND .
RENOMEIE PARA to_view_name
Renomeia a vista existente para
to_view_name.Para visualizações do Catálogo Unity, o
to_view_namedeve estar dentro do mesmo catálogo queview_name. Para outros modos de exibição, oto_view_namedeve estar dentro do mesmo esquema queview_name.Se
to_view_namenão for qualificado, é implicitamente qualificado com o esquema atual.As visões materializadas não podem ser renomeadas.
Define ou redefine uma ou mais propriedades definidas pelo usuário.
-
Remove uma ou mais propriedades definidas pelo usuário.
-
Uma consulta que constrói a visualização a partir de tabelas base ou outras visualizações.
AS querynão é suportado para visualizações métricas.Esta cláusula é equivalente a uma instrução CREATE OR REPLACE VIEW em um modo de exibição existente, exceto que os privilégios concedidos no modo de exibição são preservados.
COMO yaml_definition
Aplica-se a:
Databricks SQL
Databricks Runtime 16.4 e superior
Unity Catalog apenasUm yaml_definition para uma visualização métrica.
Esta cláusula é equivalente a uma instrução CREATE OR REPLACE VIEW em um modo de exibição existente, exceto que os privilégios concedidos no modo de exibição são preservados.
-
Aplica-se a:
Databricks SQL
Databricks Runtime 15.3 e versões posterioresDefine como a consulta subsequente da vista se adapta às alterações no esquema da vista devido a alterações nas definições dos objetos subjacentes. Veja CREATE VIEW... WITH SCHEMA para obter detalhes sobre os modos de vinculação de esquema.
Esta cláusula não é suportada para visualizações métricas.
[ SET ] PROPRIETÁRIO A principal
Transfere a propriedade da exibição para
principal. A menos que a exibição esteja definida no você só pode transferir ahive_metastorepropriedade para um grupo ao qual pertence.Aplica-se a:
Databricks SQL
Databricks Runtime 11.3 LTS e superiorSETé permitido como palavra-chave opcional.SET TAGS ( { tag_name = tag_value } [, ...] )
Aplique tags à exibição. Você precisa ter
APPLY TAGpermissão para adicionar tags à exibição.Aplica-se a:
Databricks SQL
Databricks Runtime 13.3 LTS e superiorTAGS NÃO DEFINIDAS ( tag_name [, ...] )
Remova as tags da tabela. Você precisa ter permissão
APPLY TAGpara remover tags da exibição.Aplica-se a:
Databricks SQL
Databricks Runtime 13.3 LTS e superiortag_name
Um literal
STRING. Otag_namedeve ser único dentro da vista.tag_value
Um literal
STRING.
Exemplos
-- Rename only changes the view name.
-- The source and target schemas of the view have to be the same.
-- Use qualified or unqualified name for the source and target view.
> ALTER VIEW tempsc1.v1 RENAME TO tempsc1.v2;
-- Verify that the new view is created.
> DESCRIBE TABLE EXTENDED tempsc1.v2;
c1 int NULL
c2 string NULL
# Detailed Table Information
Database tempsc1
Table v2
-- Before ALTER VIEW SET TBLPROPERTIES
> DESCRIBE TABLE EXTENDED tempsc1.v2;
c1 int null
c2 string null
# Detailed Table Information
Database tempsc1
Table v2
Table Properties [....]
-- Set properties in TBLPROPERTIES
> ALTER VIEW tempsc1.v2 SET TBLPROPERTIES ('created.by.user' = "John", 'created.date' = '01-01-2001' );
-- Use `DESCRIBE TABLE EXTENDED tempsc1.v2` to verify
> DESCRIBE TABLE EXTENDED tempsc1.v2;
c1 int NULL
c2 string NULL
# Detailed Table Information
Database tempsc1
Table v2
Table Properties [created.by.user=John, created.date=01-01-2001, ....]
-- Remove the key created.by.user and created.date from `TBLPROPERTIES`
> ALTER VIEW tempsc1.v2 UNSET TBLPROPERTIES (`created`.`by`.`user`, created.date);
-- Use `DESCRIBE TABLE EXTENDED tempsc1.v2` to verify the changes
> DESCRIBE TABLE EXTENDED tempsc1.v2;
c1 int NULL
c2 string NULL
# Detailed Table Information
Database tempsc1
Table v2
Table Properties [....]
-- Change the view definition
> ALTER VIEW tempsc1.v2 AS SELECT * FROM tempsc1.v1;
-- Use `DESCRIBE TABLE EXTENDED` to verify
> DESCRIBE TABLE EXTENDED tempsc1.v2;
c1 int NULL
c2 string NULL
# Detailed Table Information
Database tempsc1
Table v2
Type VIEW
View Text select * from tempsc1.v1
View Original Text select * from tempsc1.v1
-- Transfer ownership of a view to another user
> ALTER VIEW v1 OWNER TO `alf@melmak.et`
-- Change the view schema binding to adopt type evolution
> ALTER VIEW v1 WITH SCHEMA TYPE EVOLUTION;
-- Applies three tags to the view named `test`.
> ALTER VIEW test SET TAGS ('tag1' = 'val1', 'tag2' = 'val2', 'tag3' = 'val3');
-- Removes three tags from the view named `test`.
> ALTER VIEW test UNSET TAGS ('tag1', 'tag2', 'tag3');
-- Alter a the metric view `region_sales_metrics` defined in CREATE VIEW to drop the `total_revenue_for_open_orders` measure.
> ALTER VIEW region_sales_metrics
AS $$
version: 0.1
source: samples.tpch.orders
filter: o_orderdate > '1990-01-01'
dimensions:
- name: month
expr: date_trunc('MONTH', o_orderdate)
- name: status
expr: case
when o_orderstatus = 'O' then 'Open'
when o_orderstatus = 'P' then 'Processing'
when o_orderstatus = 'F' then 'Fulfilled'
end
- name: order_priority
expr: split(o_orderpriority, '-')[1]
measures:
- name: count_orders
expr: count(1)
- name: total_revenue
expr: SUM(o_totalprice)
- name: total_revenue_per_customer
expr: SUM(o_totalprice) / count(distinct o_custkey)
$$;
> DESCRIBE EXTENDED region_sales_metrics;
col_name data_type
month timestamp
status string
prder_priority string
count_orders bigint measure
total_revenue decimal(28,2) measure
total_revenue_per_customer decimal(38,12) measure
# Detailed Table Information
Catalog main
Database default
Table region_sales_metrics
Owner alf@melmak.et
Created Time Sun May 18 23:45:25 UTC 2025
Last Access UNKNOWN
Created By Spark
Type METRIC_VIEW
Comment A metric view for regional sales metrics.
View Text "
version: 0.1
source: samples.tpch.orders
filter: o_orderdate > '1990-01-01'
dimensions:
- name: month
expr: date_trunc('MONTH', o_orderdate)
- name: status
expr: case
when o_orderstatus = 'O' then 'Open'
when o_orderstatus = 'P' then 'Processing'
when o_orderstatus = 'F' then 'Fulfilled'
end
- name: prder_priority
expr: split(o_orderpriority, '-')[1]
measures:
- name: count_orders
expr: count(1)
- name: total_revenue
expr: SUM(o_totalprice)
- name: total_revenue_per_customer
expr: SUM(o_totalprice) / count(distinct o_custkey)
"
Language YAML
Table Properties [metric_view.from.name=samples.tpch.orders, metric_view.from.type=ASSET, metric_view.where=o_orderdate > '1990-01-01']