WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

SQL & Databases · Intermediate · question 31 of 100

What is the difference between a star schema and a snowflake schema in a data warehouse context?

📕 Buy this interview preparation book: 100 SQL & Databases questions & answers — PDF + EPUB for $5

In a data warehouse context, a star schema and a snowflake schema are both methods of organizing data into a dimensional model that supports efficient querying and analysis. While both schemas have similarities, there are some key differences between them.

A star schema is a simplified dimensional model that consists of a central fact table and a set of dimension tables that describe the facts. The fact table contains the metrics or measurements of the data, while the dimension tables contain the attributes that provide context for the facts. In a star schema, the dimension tables are denormalized, meaning that they are flattened to eliminate redundancy and improve query performance.

Here is an example of a star schema:

In this example, the "sales" table is the fact table, and the "product", "time", and "location" tables are the dimension tables. The fact table contains the sales data, while the dimension tables provide context about the products, time periods, and locations.

A snowflake schema is a more complex dimensional model that includes additional levels of normalization in the dimension tables. In a snowflake schema, the dimension tables are partially normalized, meaning that some of the data is separated into additional tables to reduce redundancy and improve data integrity. This can result in a more complex schema that is more difficult to query but provides greater flexibility for complex data analysis.

Here is an example of a snowflake schema:

In this example, the "sales" table is the fact table, and the "product", "time", and "location" tables are the dimension tables. However, the "product" table has been partially normalized into separate tables for product categories and subcategories, and the "location" table has been partially normalized into separate tables for countries and regions.

The main difference between a star schema and a snowflake schema is the level of normalization in the dimension tables. A star schema has fully denormalized dimension tables, while a snowflake schema has partially normalized dimension tables. While a star schema is simpler and easier to query, a snowflake schema provides greater flexibility and data integrity for complex data analysis. The choice between a star schema and a snowflake schema depends on the specific needs of the data warehouse and the complexity of the data being analyzed.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic SQL & Databases interview — then scores it.
📞 Practice SQL & Databases — free 15 min
📕 Buy this interview preparation book: 100 SQL & Databases questions & answers — PDF + EPUB for $5

All 100 SQL & Databases questions · All topics