CREATE VIEW

Applies to

Description

Views are based on the result-set of an SQL query. CREATE VIEW constructs a virtual table that has no physical data therefore other operations like ALTER VIEW and DROP VIEW only change metadata. (Spark SQL Language Reference CREATE VIEW)

Grammar Syntax

CREATE [ OR REPLACE ] [ [ GLOBAL ] TEMPORARY ] VIEW [ IF NOT EXISTS ] view_identifier
    create_view_clauses AS query

create_view_clauses :=
[ ( column_name [ COMMENT column_comment ], ... ) ]
[ COMMENT view_comment ]
[ TBLPROPERTIES ( property_name = property_value [ , ... ] ) ]

Sample Source Patterns

COMMENT clause

Input Code:

IN -> Databricks_01.sql
CREATE VIEW my_view
COMMENT 'This view selects specific columns from person'
AS
SELECT 
   name,
   age,
   address
FROM
   person;

Output Code:

OUT -> Databricks_01.sql
CREATE VIEW my_view
COMMENT = '{ "Description": "This view selects specific columns from person", "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "databricks",  "convertedOn": "05/29/2025",  "domain": "no-domain-provided" }}'
AS
SELECT
   name,
   age,
   address
FROM
   person;

OR REPLACE

TEMPORARY (non-GLOBAL) VIEW

IF NOT EXISTS

Columns list

Last updated