Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Si applica a: Databricks SQL
Databricks Runtime
Modifica i metadati associati alla vista. Può modificare la definizione della vista, modificare il nome di una vista impostando un nome diverso, impostando e annullando l'impostazione dei metadati della vista impostando TBLPROPERTIES
.
Per aggiungere o modificare un commento in una vista o nelle relative colonne, utilizzare COMMENT ON.
Se la visualizzazione viene memorizzata nella cache, il comando cancella i dati memorizzati nella cache della visualizzazione e tutti i relativi dipendenti che vi fanno riferimento. La cache della visualizzazione verrà riempita pigramente la prossima volta che la visualizzazione viene acceduta. Il comando lascia le dipendenze della visualizzazione non memorizzate nella cache.
Sintassi
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
Parametri
-
Identifica la visualizzazione da modificare. Se la vista non può essere trovata, Azure Databricks genera un errore TABLE_OR_VIEW_NOT_FOUND.
RINOMINA IN to_view_name
Rinomina la vista esistente in
to_view_name
.Per le viste del catalogo Unity, deve
to_view_name
trovarsi nello stesso catalogo diview_name
. Per altre viste, l'oggettoto_view_name
deve trovarsi nello stesso schema diview_name
.Se
to_view_name
non è qualificato, viene implicitamente qualificato con lo schema corrente.Non è possibile rinominare le viste materializzate.
Imposta o reimposta una o più proprietà definite dall'utente.
Annullare le proprietà della tabella
Rimuove una o più proprietà definite dall'utente.
AS Query
Un'interrogazione che costruisce la vista a partire da tabelle di base o altre viste.
AS query
non è supportato per le visualizzazioni delle metriche.Questa clausola equivale a un'istruzione CREATE OR REPLACE VIEW in una vista esistente, ad eccezione del fatto che i privilegi concessi nella vista vengono mantenuti.
AS yaml_definition
Si applica a:
Databricks SQL
Databricks Runtime 16.4 e versioni successive
solo per Unity Catalog
Un yaml_definition per una visualizzazione delle metriche.
Questa clausola equivale a un'istruzione CREATE OR REPLACE VIEW in una vista esistente, ad eccezione del fatto che i privilegi concessi nella vista vengono mantenuti.
-
Si applica a:
Databricks SQL
Databricks Runtime 15.3 e versioni successive
Specifica il modo in cui le query successive della vista si adattano alle modifiche apportate allo schema della vista a causa di modifiche apportate alle definizioni degli oggetti sottostanti. Vedere CREATE VIEW... WITH SCHEMA per informazioni dettagliate sulle modalità di associazione dello schema.
Questa clausola non è supportata per le visualizzazioni delle metriche.
[ SET ] PROPRIETARIO A principale
Trasferisce la proprietà della vista a
principal
. A meno che la vista non sia definita inhive_metastore
, puoi trasferire la proprietà solo a un gruppo a cui appartieni.Si applica a:
Databricks SQL
Databricks Runtime 11.3 LTS e versioni successive
SET
è consentito come parola chiave facoltativa.ETICHETTE SET ( { tag_name = tag_value } [, ...] )
Applicare tag alla visualizzazione. È necessario disporre
APPLY TAG
dell'autorizzazione per aggiungere tag alla visualizzazione.Si applica a:
Databricks SQL
Databricks Runtime 13.3 LTS e versioni successive
UNSET TAGS ( tag_name [, ...] )
Rimuovere i tag dalla tabella. È necessario disporre dell'autorizzazione
APPLY TAG
per rimuovere i tag dalla visualizzazione.Si applica a:
Databricks SQL
Databricks Runtime 13.3 LTS e versioni successive
tag_name
Valore letterale
STRING
. Iltag_name
deve essere univoco all'interno della visualizzazione.tag_value
Valore letterale
STRING
.
Esempi
-- 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']