Database Schemas
BY: FAIZAN IRSHAD
Schemas & Types
In the context of Power BI, a schema is a logical blueprint that
defines the structure, organization, and relationships of tables.
Following are the three common types of Schemas:
▪ Flat Schema
▪ Star Schema
▪ Snowflake Schema
Example
Let’s consider that we need to design a schema with several
interconnected tables to analyze and visualize its data
effectively. Some of the tables in the company schema are as
follows:
▪ Reseller: A table with reseller ID, contact information, and
demographic data.
▪ Regions: Stores geographical location about the customers like
region, country and city.
▪ Sales: Captures transaction data like date, sale amount,
transaction ID, and quantities sold.
▪ Products: Stores data about various products, categories, and
subcategories with Product ID.
▪ Salesperson: Records data about salespersons, employee ID,
hiring data, and designation.
Flat Schema
A Flat schema is a simple database design where all data is stored in a
single table. In this schema, each row represents a unique record, and
each column represents the record’s attributes.
For example, in our Sales table, each row represents a sales transaction,
while the various columns specify who bought the product, the date on
which it was sold, and so on. Since there is only one table in the schema,
you don’t need to manage relationships between different tables.
Advantages & Disadvantages
Advantages
The main advantage of a Flat schema is its simplicity. Since
all data is contained within one table, it’s easy to
understand, design, and maintain. Querying the database
is straightforward, as no joins or complex queries are
required.
Disadvantages
They often result in data redundancy, as the same data
may be repeated across multiple rows. This can lead to
increased storage requirements and potential data
inconsistencies.
The schema contains multiple records with repeated
information giving rise to redundant data.
It is difficult to establish meaningful relationships and
hierarchies between data elements, so it’s difficult to
perform detailed analysis.
Star schema
In this schema, a central fact table is connected to one
or more dimension tables based on the common field or
column in both fact and dimension tables.
In our example, the fact table contains quantitative
data, such as sales amounts or product quantities. In
contrast, the dimension tables store descriptive data,
such as customer information, product details, or dates.
Star schema
Advantages & Disadvantages
Advantages
One advantage is that it reduces data redundancy by separating facts
and dimensions into distinct tables. This separation also allows for more
efficient querying and aggregation of data, as dimension tables are
typically smaller in size and can be indexed to improve query
performance.
Furthermore, the Star schema is highly intuitive and easy to understand.
The fact table serves as the focal point of the schema, and all other
tables are linked to it through clear relationships.
Disadvantages
On the downside, the Star schema can be less flexible than other
schema types. For example, actions like adding new dimensions or
modifying existing ones may require extensive changes to the schema.
Also, the Star schema may not be suitable for handling complex
relationships between dimensions. The Snowflake schema better
accommodates greater levels of complexity.
Snowflake schema
A Snowflake schema is an extension of the Star schema. In
this schema, dimension tables are split into multiple related
tables to reduce data redundancy and improve data
integrity. This process is referred to as normalization.
In the our example, each dimension table is connected to
one or more related tables, forming a hierarchical structure
that resembles a Snowflake.
Snowflake Schema
Advantages & Disadvantages
Advantages
The Snowflake schema offers several benefits, including
reduced data redundancy and improved data integrity
due to the normalization of dimension tables.
This schema also provides greater flexibility in handling
complex relationships between dimensions, as new tables
can be easily added to accommodate new relationships.
Disadvantages
The Snowflake schema is more complex than the Star
schema. This makes it harder to understand and maintain.
Querying a Snowflake schema can be more challenging
and time-consuming. This is because multiple join
operations may be required to retrieve data from the
related tables.
Thankyou