Lesson 69/100

Tutorials SQL Server Tutorial

Data Compression — Complete Guide

Data Compression — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of SQL Server Tutorial on Toolliyo Academy.

On this page

SQL Server Tutorial · Lesson 69 of 100

Data Compression

SQL basics ✓Queries ✓Advanced

Advanced · 3 — Procedures · ~10 min · SQL — Advanced SQL Server

What is this?

ROW or PAGE compression stores table/index data more densely to save space and sometimes reduce IO at the cost of CPU.

Why should you care?

Large historical tables benefit when disk and backup size dominate cost.

See it live — copy this example

Run in SQL Server Management Studio (SSMS) or Azure Data Studio.

USE DataVerse;
ALTER TABLE dbo.FactOrderDaily REBUILD WITH (DATA_COMPRESSION = PAGE);
SELECT p.data_compression_desc, i.name
FROM sys.partitions p
JOIN sys.indexes i ON i.object_id = p.object_id AND i.index_id = p.index_id
WHERE p.object_id = OBJECT_ID(N'dbo.FactOrderDaily');

What happened?

  • REBUILD applies PAGE compression to the table’s indexes/partitions.
  • Catalog views confirm the setting.
  • Test CPU vs IO on your workload.

Practice next

  1. Compress FactOrderDaily with PAGE in lab.
  2. Verify data_compression_desc.
  3. Run an aggregate and note CPU time vs before.
  4. Try DATA_COMPRESSION = ROW and compare size.
  5. sp_estimate_data_compression_savings in lab.

Remember

ROW/PAGE compression save space. Trade CPU for IO. Measure before rolling out widely.

Archive fact compression

DataVerse old fact partitions use PAGE compression.

Outcome: Backups shrink; queries stay acceptable.

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Mid PDF Detailed
What are the differences between SQL and NoSQL databases?
Short answer: SQL Databases (Relational Databases): These are structured databases that use Structured Query Language (SQL) for defining and manipulating data. Explain a bit more They store data in tables with rows and c…
Mid PDF Detailed
Slower Queries: Fragmented indexes cause the database engine to read more data?
Short answer: pages, slowing down query performance. Real-world example (ShopNest) ShopNest adds an index on Orders(CustomerId, CreatedAt) because “my recent orders” is queried constantly. Say this in the interview Defin…
Junior PDF Detailed
What are the differences between SQL and NoSQL databases?
Short answer: And allow storage of unstructured or semi-structured data. They don't require a fixed schema and are often used for large-scale applications where flexibility, scalability, nd speed are more important than…
Mid PDF Detailed
Shared Database, Shared Schema:?
Short answer: All tenants share the same database and tables. A tenant identifier (e.g., tenant_id) is used to segregate data. Pros: Easier to maintain and scale. Cons: Can lead to security and data isolation issues. Say…
Mid PDF Detailed
Normalize the Database: Apply normalization rules (1NF, 2NF, 3NF) to reduce?
Short answer: redundancy by eliminating unnecessary duplication. Real-world example (ShopNest) Product and Category are separate tables (normalized). The order line stores product id + price snapshot—not a giant duplicat…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

SQL Server Tutorial
Course syllabus

SQL Server Tutorial

SQL — Foundations
SQL — SQL Queries & Clauses
SQL — Joins & Relationships
SQL — Indexing & Performance
SQL — Stored Procedures & Functions
SQL — Transactions & Concurrency
SQL — Advanced SQL Server
SQL — Security & High Availability
SQL — 2022 & Cloud
SQL — Real-World Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details