Semantic Views & Cortex Analyst

Snowflake · Advanced Features

Theory

A semantic view is a schema-level object that describes your data in business terms: logical TABLES, the RELATIONSHIPS between them, FACTS, DIMENSIONS such as city or order_date, and METRICS such as total_sales = SUM(amount). Because the meaning lives in one governed object, every tool asks for total_sales the same way. You can query it with SELECT * FROM SEMANTIC_VIEW(sales_sv METRICS orders.total_sales DIMENSIONS customers.city).

Cortex Analyst uses that semantic model to answer natural-language questions. Asked "What were sales by city last month?", it generates SQL from the definitions, runs it on your warehouse and returns the result. It is offered as a REST API and as a tool inside Cortex Agents, which Snowflake now recommends for new conversational apps. Older semantic models written as YAML files on a stage still work.

Why we use it

Letting business users ask questions in plain English only works if the AI knows what each table, join and metric means. Semantic views give it that context once, so answers are consistent and governed instead of guessed from column names.

When to use it

Use semantic views to define shared metrics for BI and AI, and Cortex Analyst (usually through Cortex Agents) for self-service questions over structured data. Use Cortex Search for unstructured text. Keep critical reports on reviewed SQL and verify generated answers.

How it works

  1. Business user asks a question in plain English
  2. Cortex Analyst reads the semantic view: tables, relationships, metrics
  3. It generates SQL for the question
  4. Is the question answerable with the defined data? Yes: Run the SQL on the user's warehouse. No: Ask the user to clarify or decline.
  5. Results respect the user's role and policies
  6. Answer and the generated SQL are returned

Example

CREATE OR REPLACE SEMANTIC VIEW sales_sv
  TABLES (
    orders AS sales_db.public.orders PRIMARY KEY (order_id),
    customers AS sales_db.public.customers PRIMARY KEY (customer_id)
  )
  RELATIONSHIPS (
    orders_to_customers AS orders (customer_id) REFERENCES customers
  )
  FACTS (
    orders.order_amount AS amount
  )
  DIMENSIONS (
    customers.city AS city,
    orders.order_date AS order_date
  )
  METRICS (
    orders.total_sales AS SUM(orders.order_amount)
  )
  COMMENT = 'Sales metrics for BI and Cortex Analyst';

SELECT * FROM SEMANTIC_VIEW(
  sales_sv
    DIMENSIONS customers.city
    METRICS orders.total_sales
);

Key points

Snowflake topics

Snowflake Fundamentals

Warehouses & Performance

Staging & SnowSQL

Tables & Data Handling

Cloud Integrations

Storage & Optimization

Security & Governance

Views, Pipelines & Automation

Data Types & SQL Fundamentals

Semi-Structured Data Deep Dive

Advanced Features

Data Sharing & Collaboration

Cost Management & Monitoring

Databases, Schemas & Objects

Performance Deep Dive

Advanced Security & Governance

Stored Procedures & UDFs

Ecosystem & Integrations

SnowPro Certification Prep

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Mastering Snowflake

The modern data cloud, from architecture to SnowPro certification. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Snowflake SQL Sharpen the SQL you use in Snowflake: 150 query problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Snowflake  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

{{ sec.h }}

{{ sec.body }}

{{ sec.body }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
On screen — where to click

{{ rich.ui.title }}

{{ u.text }}
  1. {{ st.n }}{{ st.text }}
{{ rich.ui.title }}
{{ u.text }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
Want to run this yourself? Unlike the SQL and Python courses, Snowflake needs a real account — there's no in-browser engine for it. Click Copy above, then paste it into a free Snowflake trial (30 days, no card required) and run it in Snowsight.
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic