Uwaga
Dostęp do tej strony wymaga autoryzacji. Może spróbować zalogować się lub zmienić katalogi.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
Dotyczy: Databricks SQL
Databricks Runtime
Zmienia metadane skojarzone z widokiem. Może zmienić definicję widoku, zmienić nazwę widoku na inną nazwę, ustawić i usunąć ustawienia metadanych widoku, ustawiając TBLPROPERTIES
.
Aby dodać lub zmienić komentarz w widoku lub jego kolumnach, użyj COMMENT ON.
Jeśli widok jest buforowany, polecenie czyści buforowane dane widoku i wszystkie jego zależności odwołujące się do niego. Pamięć podręczna widoku zostanie wypełniona z opóźnieniem po następnym korzystaniu z widoku. Polecenie pozostawia zależności widoku jako niebuforowane.
Składnia
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
Parametry
-
Identyfikuje widok, który ma zostać zmieniony. Jeśli nie można odnaleźć widoku usługi Azure Databricks, wystąpi błąd TABLE_OR_VIEW_NOT_FOUND .
ZMIEŃ NAZWĘ NA TO_VIEW_NAME
Zmienia nazwę istniejącego widoku na
to_view_name
.W przypadku widoków Unity Catalog,
to_view_name
musi znajdować się w tym samym katalogu coview_name
. W przypadku innych widoków,to_view_name
musi być w tym samym schemacie coview_name
.Jeśli
to_view_name
jest niekwalifikowany, jest domyślnie kwalifikowany przy użyciu obecnego schematu.Nie można zmienić nazwy zmaterializowanych widoków.
Ustawia lub resetuje co najmniej jedną właściwości zdefiniowaną przez użytkownika.
-
Usuwa co najmniej jedną właściwości zdefiniowaną przez użytkownika.
-
Zapytanie, które konstruuje widok z tabel podstawowych lub innych widoków.
AS query
nie jest obsługiwana w przypadku widoków metryk.Ta klauzula jest równoważna instrukcji CREATE OR REPLACE VIEW w istniejącym widoku, z tą różnicą, że uprawnienia przyznane w widoku są zachowywane.
As yaml_definition
Dotyczy:
Databricks SQL,
Databricks Runtime 16.4 i nowsze,
tylko katalog Unity
Definicja YAML dla widoku metryki.
Ta klauzula jest równoważna instrukcji CREATE OR REPLACE VIEW w istniejącym widoku, z tą różnicą, że uprawnienia przyznane w widoku są zachowywane.
-
Dotyczy:
Databricks SQL
Databricks Runtime 15.3 lub nowszy
Określa, jak kolejne wykonywanie zapytań w widoku dostosowuje się do zmian w schemacie widoku ze względu na zmiany w definicjach obiektów bazowych. Zobacz CREATE VIEW... WITH SCHEMA , aby uzyskać szczegółowe informacje na temat trybów powiązań schematu.
Ta klauzula nie jest obsługiwana w przypadku widoków metryk.
[ SET ] WŁAŚCICIEL DO głównego podmiotu
Przenosi własność widoku na
principal
. Chyba że widok jest zdefiniowany w elemeciehive_metastore
, użytkownik może przenieść własność tylko do grupy, do której należysz.Dotyczy:
Databricks SQL
Databricks Runtime 11.3 LTS i nowsze
SET
jest dozwolone jako opcjonalne słowo kluczowe.SET TAGI ( { tag_name = tag_value } [, ...] )
Zastosuj tagi do widoku. Musisz mieć
APPLY TAG
uprawnienia do dodawania tagów do widoku.Dotyczy:
Databricks SQL
Databricks Runtime 13.3 LTS i nowsze
UNSET TAGS (TAG_NAME [, ...] )
Usuń tagi z tabeli. Musisz mieć uprawnienia
APPLY TAG
do usuwania tagów z widoku.Dotyczy:
Databricks SQL
Databricks Runtime 13.3 LTS i nowsze
tag_name
Literał
STRING
. Elementtag_name
musi być unikatowy w widoku.tag_value
Literał
STRING
.
Przykłady
-- 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']