Tutorials SQL Server Tutorial

Database Files — Complete Guide

Database Files — 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 7 of 100

Database Files

SQL basicsQueriesAdvanced

SQL basics · 1 — SELECT · ~6 min · SQL — Foundations

What is this?

Each database has at least one data file (.mdf) and one log file (.ldf). Data pages live in the data file; the log records changes for recovery.

Why should you care?

Full disks and slow logs cause outages. Knowing which file grew tells you whether to add space or fix a long transaction.

See it live — copy this example

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

USE DataVerse;
SELECT
    df.name AS LogicalName,
    df.type_desc,
    df.physical_name,
    CAST(df.size * 8.0 / 1024 AS DECIMAL(10,2)) AS SizeMB
FROM sys.database_files AS df;

What happened?

  • sys.database_files lists logical names, ROWS vs LOG, OS path, and size in MB.
  • You see exactly where your database stores bytes on disk.

Practice next

  1. USE your database and run the query.
  2. Note the .mdf and .ldf paths.
  3. In SSMS, right-click your database → Properties → Files and compare.
  4. Add df.max_size and df.growth to the SELECT list.
  5. Compare sizes after creating a large test table (then drop it).

Remember

Data file holds tables; log file holds recovery records. sys.database_files shows path and size. Watch disk space on those paths.

Log full during big import

A DataVerse ETL left an open transaction and the .ldf filled the disk.

Outcome: Team fixed the transaction and moved log to a larger volume.

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