What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
To build a semantic view over three related Snowflake tables, you map each physical table to a logical table, declare how the tables join, define dimensions for the attributes you group by and metrics for the measures you aggregate, and then run CREATE OR REPLACE SEMANTIC VIEW. You query it with SEMANTIC_VIEW(...) and check its structure with DESCRIBE SEMANTIC VIEW. This tutorial follows the three-table pattern in Snowflake’s documentation, which uses orders, customers, and line items built on the TPC-H sample data.
What a semantic view does
A semantic view is a schema-level object that describes business entities, the relationships between them, and the analytical concepts people use to ask questions. Snowflake’s overview of semantic views describes the workflow as four stages: design the business data model, map business concepts to physical tables, create the semantic view, and then use it for analysis.
Two kinds of concept do most of the work. A dimension is an attribute you group, filter, or inspect by, such as a customer name or an order date. A metric is a measure you quantify through an aggregation such as SUM, AVG, or COUNT, such as total revenue. A semantic view must contain at least one dimension or metric.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Plan the three logical tables before writing SQL
Snowflake’s recommended starting point is a simple star schema: one table that holds the measures, surrounded by the tables that describe them. The official example uses the TPC-H sample tables and gives each one a logical name. The table below shows how the pieces fit together.
#1 Best Overall
| Logical table | Physical source (TPC-H) | Key used for relationships | Role in the model | Example dimension or metric |
|---|---|---|---|---|
orders |
orders |
o_orderkey (primary key); o_custkey points to customers |
Order-level attributes; links line items to customers | Dimension: order_date from o_orderdate |
customers |
customer |
c_custkey (primary key) |
Descriptive attributes about the buyer | Dimension: customer_name from c_name |
line_items |
lineitem |
l_orderkey plus l_linenumber (composite primary key); l_orderkey points to orders |
Measure anchor, because revenue is recorded per line | Metric: total_revenue as SUM of extended price after discount |
Choose the anchor table first. The line items table is the natural anchor here because revenue is stored at line level, and summing it at that grain gives correct totals. Customers and orders supply the attributes you slice by. If you start from a descriptive table instead, your metrics will usually need extra care to avoid double counting when joins fan out.
For each table, confirm that the key really identifies rows. A key that repeats within the physical table will make the relationship declaration wrong even if the SQL runs.
Build the view step by step
1. Map physical tables to logical tables
In the TABLES clause, give each logical table a name, bind it to a physical table, and declare its primary key. The example below assumes the TPC-H sample tables are reachable through Snowflake’s sample database. If your account exposes them under another database or schema name, change the paths accordingly.
Rank #2
2. Declare relationships
The RELATIONSHIPS clause defines how logical tables connect. Each relationship names the foreign-key columns on one table and the table it references. Check that the columns you list express the real data model: a relationship on a non-unique column will not behave like a many-to-one link. Primary keys and unique columns are what Snowflake uses to determine how the tables relate.
3. Expose dimensions and metrics
Dimensions go in the DIMENSIONS clause and metrics in the METRICS clause. Each entry is qualified with its logical table, so Snowflake knows where the concept lives. Keep metrics for aggregated expressions and dimensions for attributes. If you have a row-level calculation that several metrics reuse, Snowflake also supports facts, which represent underlying values you can build on.
4. Create the view
Put the clauses together with CREATE OR REPLACE SEMANTIC VIEW. The statement below follows the structure of Snowflake’s three-table example, with the TPC-H column names filled in. Compare it against the official example and the SQL command guide before you run it in your own account, because clause details can change between releases.
Rank #3
CREATE OR REPLACE SEMANTIC VIEW tpch_sales_sv
TABLES (
orders AS snowflake_sample_data.tpch_sf1.orders
PRIMARY KEY (o_orderkey),
customers AS snowflake_sample_data.tpch_sf1.customer
PRIMARY KEY (c_custkey),
line_items AS snowflake_sample_data.tpch_sf1.lineitem
PRIMARY KEY (l_orderkey, l_linenumber)
)
RELATIONSHIPS (
line_items_to_orders AS
line_items (l_orderkey) REFERENCES orders,
orders_to_customers AS
orders (o_custkey) REFERENCES customers
)
DIMENSIONS (
customers.customer_name AS customers.c_name,
orders.order_date AS orders.o_orderdate
)
METRICS (
line_items.total_revenue AS
SUM(line_items.l_extendedprice * (1 - line_items.l_discount))
);
This view has two relationships in a chain, line items to orders and orders to customers. That chain gives exactly one path from the revenue measure to any customer attribute, which keeps the model unambiguous.
Query and inspect the view
Query a semantic view with SEMANTIC_VIEW(...), naming the view and then the dimensions and metrics you want. A metric and a dimension that have one clear relationship path can be combined directly. The query below asks for revenue by customer name, and the path from line items through orders to customers is the only one in this model.
SELECT *
FROM SEMANTIC_VIEW(
tpch_sales_sv
DIMENSIONS customers.customer_name
METRICS line_items.total_revenue
);
The result has one row per customer name, with the summed revenue for that customer. Adding orders.order_date to the dimensions list works the same way, because orders is one hop from line items.
To check what you created, run DESCRIBE SEMANTIC VIEW tpch_sales_sv;. The output describes the logical tables, relationships, facts, dimensions, metrics, and the view itself. Use it to confirm that each relationship points where you intended and that each metric sits on the table you meant to anchor it to. See the DESCRIBE SEMANTIC VIEW reference for the full output format.
Modeling decisions to settle before you create the view
- Which table anchors each measure? The anchor should be the grain at which the measure is recorded. Other tables supply descriptive attributes.
- Which columns identify rows and serve as relationship keys? Confirm uniqueness in the physical data, not just in the design document.
- Which fields are dimensions and which are metrics? Anything you group or filter by is a dimension. Anything you aggregate is a metric.
- Can a metric reach a selected dimension along more than one path? If yes, the path is ambiguous and must be resolved explicitly, as covered in the next section.
- Is the metric additive across every dimension? Snowflake documents non-additive dimensions for cases where summing a measure across a dimension gives a misleading result. A point-in-time balance is the typical example: summing account balances across months double-counts the same balance. Declare such dimensions as non-additive so the calculation does not silently sum them.
Permissions and availability
To create or replace a semantic view, Snowflake’s SQL command guide states: “To create or replace a semantic view, you must use a role with the following privileges:” The privileges listed are:
CREATE SEMANTIC VIEWon the destination schemaUSAGEon the database and on the schemaSELECTon the tables or views the semantic view uses
The CREATE SEMANTIC VIEW reference labels semantic views as a preview feature available to all accounts. Preview status can change, so confirm it on that page before you rely on the feature for production reporting.
Best Value
Query behavior and troubleshooting
When a single query names both a dimension and a metric, Snowflake requires that the dimension’s logical table is related to the metric’s logical table. The querying guide makes this a condition for a valid query.
The problem shows up when two tables are connected by more than one relationship. Snowflake’s SQL guide illustrates this with flights and airports: two different relationships link the flights table to the airports table, so a query that pairs an airport dimension with a flight metric has two possible paths. The fix is to put a USING clause on the metric that names the relationship you intend. The relationship named in USING must start from the logical table that contains the metric. In the flights example, that means a relationship that begins at flights, not one that begins at airports.
Use this checklist when a query fails or returns a result that does not match the question:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minute- Error about an invalid or ambiguous path: Two relationships connect the metric’s table and the dimension’s table. Add
USINGto the metric and name the relationship that matches your question. - Dimension and metric are not related: No relationship path links the two logical tables. Add the missing relationship in
RELATIONSHIPS, or pick a dimension that is reachable from the metric’s table. - Totals look too high: A join fans out, or a metric that should be non-additive is being summed across a dimension. Revisit the anchor table and the non-additive declaration.
- Creation fails with no clear reason: Check that the view has at least one dimension or metric, and confirm the role has the three privileges listed above.
The examples in Snowflake’s documentation show the syntax and the behavior, not output from a particular account. When you adapt them, run DESCRIBE SEMANTIC VIEW first and then test one metric against one dimension before you build dashboards on the view.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

