ALTER VIEW
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 in modo pigro quando si accede alla visualizzazione la volta successiva. Il comando lascia gli elementi dipendenti della visualizzazione non memorizzati 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
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 all'interno dello schema. Non è possibile rinominare le viste materializzate.
to_view_name specifica il nuovo nome della visualizzazione. Se l'oggetto
to_view_name
esiste già, viene generato un oggettoTableAlreadyExistsException
. Seto_view_name
è qualificato, deve corrispondere al nome dello schema diview_name
.-
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.
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 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.
[ 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');