적용 대상:
Databricks SQL
Databricks Runtime
뷰와 연결된 메타데이터를 변경합니다. 뷰의 정의를 변경하고, 보기의 이름을 다른 이름으로 변경하고, TBLPROPERTIES설정하여 보기의 메타데이터를 설정하고 설정 해제할 수 있습니다.
보기에 주석을 추가하거나 변경하려면 다음을 사용합니다 COMMENT ON.
뷰가 캐시된 경우 이 명령은 뷰의 캐시된 데이터와 뷰를 참조하는 모든 종속 항목을 지웁니다. 다음에 보기에 접근할 때, 보기에 대한 캐시는 필요에 따라 지연되면서 채워질 것입니다. 이 명령은 뷰의 종속을 캐시되지 않은 상태로 둡니다.
구문
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
매개 변수
-
변경할 뷰를 식별합니다. 뷰를 찾을 수 없으면 Azure Databricks에서 TABLE_OR_VIEW_NOT_FOUND 오류가 발생합니다.
이름을 to_view_name으로 변경
기존 보기
to_view_name의 이름을 .로 바꿉니다.Unity 카탈로그 뷰의 경우 동일한
to_view_name카탈로그view_name내에 있어야 합니다. 다른 보기의 경우 해당 뷰는to_view_name.와 동일한 스키마view_name내에 있어야 합니다.정규화되지 않은 경우
to_view_name현재 스키마를 사용하여 암시적으로 정규화됩니다.구체화된 뷰의 이름을 바꿀 수 없습니다.
하나 이상의 사용자 정의 속성을 설정 또는 다시 설정합니다.
-
사용자 정의 속성을 하나 이상 제거합니다.
AS 쿼리
기본 테이블 또는 다른 뷰에서 뷰를 생성하는 쿼리입니다.
AS query는 메트릭 뷰에 대해 지원되지 않습니다.이 절은 뷰에 부여된 권한이 유지된다는 점을 제외하고 기존 뷰의 CREATE OR REPLACE VIEW 문과 동일합니다.
AS yaml_definition
적용 대상:
Databricks SQL
Databricks Runtime 16.4 이상
Unity Catalog 전용메트릭 뷰의 YAML 정의.
이 절은 뷰에 부여된 권한이 유지된다는 점을 제외하고 기존 뷰의 CREATE OR REPLACE VIEW 문과 동일합니다.
-
다음에 적용됨:
Databricks SQL
Databricks Runtime 15.3 이상기본 개체 정의의 변경으로 인해 뷰의 후속 쿼리가 보기의 스키마 변경 내용에 맞게 조정되는 방식을 지정합니다. CREATE VIEW의 스키마 바인딩 모드에 대한 자세한 내용은 SCHEMA을 참조하십시오.
메트릭 뷰에는 이 절이 지원되지 않습니다.
[ SET ] 소유자 책임자
뷰의 소유권을
principal로 이전합니다.hive_metastore에 뷰가 정의되지 않은 경우 사용자가 속한 그룹에만 소유권을 이전할 수 있습니다.적용 대상:
Databricks SQL
Databricks Runtime 11.3 LTS 이상SET는 선택적 키워드로 허용됩니다.SET TAGS ( { tag_name = tag_value } [, ...] )
보기에 태그를 적용합니다. 뷰에
APPLY TAG태그를 추가할 수 있는 권한이 있어야 합니다.적용 대상:
Databricks SQL
Databricks Runtime 13.3 LTS 이상설정 해제 태그 ( tag_name [, ...] )
테이블에서 태그를 제거합니다. 보기에서 태그를 제거하려면
APPLY TAG권한이 있어야 합니다.적용 대상:
Databricks SQL
Databricks Runtime 13.3 LTS 이상tag_name
리터럴
STRING입니다.tag_name뷰 내에서 고유해야 합니다.tag_value
리터럴
STRING입니다.
예제
-- 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']