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 basics → Queries → Advanced
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
- USE your database and run the query.
- Note the .mdf and .ldf paths.
- In SSMS, right-click your database → Properties → Files and compare.
- Add df.max_size and df.growth to the SELECT list.
- 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.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!