적용 대상:
Databricks SQL
Databricks Runtime
뷰와 연결된 메타데이터를 변경합니다. 뷰의 정의를 변경하고, 보기의 이름을 바꾸고, 설정하여 TBLPROPERTIES메타데이터를 설정하거나 설정 해제할 수 있습니다. 메트릭 뷰에서는 관계(Beta)를 추가하거나 삭제할 수도 있습니다.
보기에 주석을 추가하거나 변경하려면 다음을 사용합니다 COMMENT ON.
뷰가 캐시된 경우 이 명령은 뷰의 캐시된 데이터와 뷰를 참조하는 모든 종속 항목을 지웁니다. 보기의 캐시는 다음에 보기에 액세스할 때 지연으로 채워집니다. 이 명령은 뷰의 종속을 캐시되지 않은 상태로 둡니다.
필수 권한
Unity 카탈로그를 사용하는 경우 다음 작업에 뷰의 소유권이 필요하지 않습니다.
-
SET TAGS: 권한이 필요합니다APPLY TAG. -
UNSET TAGS: 권한이 필요합니다APPLY TAG.
다음 작업을 수행하려면 뷰의 소유권이 필요합니다.
SET TBLPROPERTIESUNSET TBLPROPERTIES-
AS query(보기 정의 변경) -
WITH SCHEMA(스키마 바인딩 변경)
RENAME TO 에는 보기에 MANAGE 대한 권한이 필요합니다.
ADD CONSTRAINT
DROP CONSTRAINT 그리고 그 메트릭 뷰 또는 소유권, 그리고 USE CATALOGUSE SCHEMA 카탈로그 및 스키마에 대한 권한을 요구 MANAGE 합니다.
ADD CONSTRAINT관계 관계에는 대상 메트릭 뷰, 그리고 USE CATALOGUSE SCHEMA 대상 카탈로그 및 스키마에 대한 권한이 필요합니다SELECT.
필요한 SET OWNER TO권한은 새 소유자에 따라 달라집니다.
- 보안 주체가 본인인 경우 보기에
MANAGE대한 권한이 있어야 합니다. - 보안 주체가 그룹인 경우 해당 그룹의 구성원이어야 합니다.
- 다른 모든 경우에는 metastore 관리자여야 합니다.
구문
ALTER VIEW view_name
{ rename |
SET TBLPROPERTIES clause |
UNSET TBLPROPERTIES clause |
alter_body |
schema_binding |
owner_to |
SET TAGS clause |
UNSET TAGS clause |
add_constraint |
drop_constraint }
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
{ identifier [. ...] | string_literal }
owner_to
[ SET ] OWNER TO principal
add_constraint
ADD [ CONSTRAINT name ] relationship_constraint
relationship_constraint
cardinality RELATIONSHIP TO target_view [ [ AS ] target_alias ]
{ ON condition | USING ( column [, ...] ) }
cardinality
{ MANY | ONE } TO { MANY | ONE }
drop_constraint
DROP CONSTRAINT [ IF EXISTS ] name
매개 변수
-
변경할 뷰를 식별합니다. 보기를 찾을 수 없으면 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현재 스키마를 사용하여 암시적으로 정규화됩니다.구체화된 뷰의 이름을 바꿀 수 없습니다.
SET TBLPROPERTIES(TBLPROPERTIES)
하나 이상의 사용자 정의 속성을 설정 또는 다시 설정합니다.
-
사용자 정의 속성을 하나 이상 제거합니다.
AS 쿼리
기본 테이블 또는 다른 뷰에서 뷰를 생성하는 쿼리입니다.
AS query는 메트릭 뷰에 대해 지원되지 않습니다.이 절은 뷰에 부여된 권한이 유지된다는 점을 제외하고 기존 뷰의 CREATE OR REPLACE VIEW 문과 동일합니다.
그yaml_definition
적용 대상:
Databricks SQL
Databricks Runtime 16.4 이상
Unity Catalog 전용메트릭 뷰의 YAML 정의.
이 절은 뷰에 부여된 권한이 유지된다는 점을 제외하고 기존 뷰의 CREATE OR REPLACE VIEW 문과 동일합니다.
YAML 정의를 다시 지정하면 구문 변경 없이 메트릭 뷰가
parameters추가, 삭제 또는 변경됩니다. 매개 변수 구문은 .를 참조하세요 CREATE VIEW. 매개 변수에는 Databricks Runtime 18.2 이상이 필요합니다.-
다음에 적용됨:
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입니다.add_constraint
적용 대상:
브릭스 SQL 확인
브릭스 런타임 19 이상
완료 Unity 카탈로그 전용메트릭 뷰에서 타겟 메트릭 뷰로의 정보 관계를 추가합니다. 이 조항은 베타 버전입니다. 둘 다
view_name그리고target_view반드시 Unity Catalog 메트릭 뷰여야 합니다. 임시 메트릭 뷰는 지원되지 않습니다. Azure Databricks는 관계를 강제하지 않습니다. 메 트릭 뷰 간의 관계(Relationships between Metric Views)를 참조하세요.CONSTRAINT 이름
선택적으로 관계 이름을 붙일 수 있습니다. 이름은 스키마 내 모든 제약 조건 중에서 유일해야 합니다. 만약 이 뷰를 누락하면, Azure Databricks는 두 메트릭 뷰의 무제한 이름을 사용하여 관계를
<source>_to_<target>명명합니다.카디널리티
MANY TO ONE,ONE TO MANY,ONE TO ONE, 또는MANY TO MANY중 하나. Azure Databricks는 데이터를 카디널리티와 비교하지 않습니다.-
대상 메트릭 뷰를 식별합니다. 타겟은 동일한 메타스토어의 어떤 카탈로그나 스키마에도 있을 수 있습니다.
target_alias
선택적으로 대상
condition을 에 명명할 수 있습니다. 거리 관점에서 자기 자신과의 관계는 의view_name이름과 다른 별칭을 필요로 한다.조건
와 의 열에 대한 결정론적
BOOLEAN표현식으로, 조인의 절과ON동일한 규칙을 가진다.view_nametarget_view이 표현은 박자를 가리킬 수 없습니다. MEASURE와 AGG를 포함한 집계 함수, 윈도우 함수, 생성기를 호출할 수 없습니다. 최대 1,024자까지 가능합니다.사용 중입니다 (열[, ...])
두 메트릭 뷰에서 같은 이름을 가진 열이 1개에서 20개까지 존재합니다.
drop_constraint
적용 대상:
브릭스 SQL 확인
브릭스 런타임 19 이상
완료 Unity 카탈로그 전용미터법 관점에서 관계를 제거
name하죠. 이 조항은 베타 버전입니다. 만약 를 지정IF EXISTS하면, 해당 명칭과 관련된 관계가 존재하지 않을 때 이 문장은 성공합니다. 그렇지 않으면NO_SUCH_CONSTRAINT_EXCEPTION.Warning
언제 관계를 끝내는지,
CASCADE구체적으로RESTRICT말하지 마세요. ALTER TABLE DROP CONSTRAINT반면, 이 키워드는 관계에 대한 정의된 행동이 없으며, 향후 릴리스에서 그 행동이 바뀔 수 있습니다.
예제
-- Rename only changes the view name.
-- The source and target schemas of the view must 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;
-- Apply three tags to the view named `test`.
> ALTER VIEW test SET TAGS ('tag1' = 'val1', 'tag2' = 'val2', 'tag3' = 'val3');
-- Remove three tags from the view named `test`.
> ALTER VIEW test UNSET TAGS ('tag1', 'tag2', 'tag3');
-- Alter 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
order_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: 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)
"
Language YAML
Table Properties [metric_view.from.name=samples.tpch.orders, metric_view.from.type=ASSET, metric_view.where=o_orderdate > '1990-01-01']
-- Declare that each order in the `orders_mv` metric view matches one customer
-- in the `customers_mv` metric view, joined on the shared `customer_id` column.
> ALTER VIEW main.sales.orders_mv ADD CONSTRAINT orders_customer
MANY TO ONE RELATIONSHIP TO main.sales.customers_mv
USING (customer_id);
-- Declare a relationship that refers to the target by an alias in the ON condition.
> ALTER VIEW main.travel.flights_mv ADD CONSTRAINT departure_city
MANY TO ONE RELATIONSHIP TO main.travel.cities_mv AS c
ON flights_mv.departure_city_id = c.city_id;
-- Drop the relationship.
> ALTER VIEW main.travel.flights_mv DROP CONSTRAINT IF EXISTS departure_city;