Lesson 1
Introduction to Database Concepts
Module 1 covered the stack this course builds on, Visual Studio 2026, ASP.NET Core Razor Pages on .NET 10, C#, and SQL Server 2025, and introduced VirtualBookShelf, the online bookstore project you'll build throughout the course. This module shifts from that setup work to the database concepts underneath it: what a relational database actually looks like, how your pages will reach one, and what SQL does once they get there. None of this module requires writing a line of C# yet. Before you connect a Razor Page to a database, it helps to understand what's actually on the other end of that connection.
The Modern Internet
The web offers a remarkable range of things you can do from a browser: shopping, researching almost any topic, booking travel, buying and selling stocks, or bidding in an online auction. The ease of navigating through all of that conceals the complex engineering running behind the scenes.
A good example is shopping for a new car. A manufacturer's web site lets you view any model in any color, read about performance, options, and pricing, and custom-configure your preferred trim down to the sticker price, right to the penny. Then you can comparison shop by visiting another site entirely and finding a dealer with a better price in your area.
None of that is magic. Every one of those pages, the configurator, the price calculator, the dealer locator, is a web page asking a database a question and rendering the answer as HTML. That's the pattern this entire course is built around, and it's worth keeping in view: behind almost every genuinely useful page on the web, there's a database, and a piece of server-side code asking it something specific.
Introduction to Database Concepts
Sites like the car manufacturer's example above frequently query and display data from large databases. That data includes:
- text,
- images,
- audio, and
- even other web pages.
Most web sites today incorporate some type of database, from something as simple as a text file to a very large relational database system. Data is what the web is about. Sites exist to provide data to users and to collect data back from them. Web pages and data are practically synonymous, and the VirtualBookShelf project you started in Module 1 is a small, concrete example of exactly that: pages that show book and customer data, and forms that collect it.
This module introduces the basic database concepts you need before adding database functionality to a Razor Pages application. By the time you finish this module, you should be able to do the following:
- Identify table structures used in relational databases
- Identify common database systems
- Recognize ADO.NET, Entity Framework Core, and ODBC as database access solutions
- Explain what SQL is and what it does
- Configure a connection string for a data source in a project
- Bind query results to a Razor Page using model binding and Tag Helpers
In the next lesson, the storage of data will be discussed.
Table Structures: What a Relational Database Actually Looks Like
A relational database stores data in tables, and a table is simpler than it might sound: rows and columns, the same shape as a spreadsheet, with two important differences. Every row in a well-designed table represents exactly one thing, one customer, one book, and every column holds exactly one kind of value for that thing. The VirtualBookShelf project's Inventory table, introduced in Module 1, Lesson 3, is a working example:
| BookID | Title | Author | ISBN | Price | QuantityOnHand |
| 1 | The Pragmatic Programmer | David Thomas | 9780135957059 | 44.99 | 12 |
| 2 | Clean Code | Robert C. Martin | 9780132350884 | 39.99 | 7 |
Each row is one book. Each column holds one fact about that book: its title, its author, its price.
BookID is the table's primary key, a column (or combination of columns) guaranteed to be unique for every row, which is what lets a query or a Razor Page refer to exactly one book without ambiguity. Customer works the same way, with
CustomerID as its own primary key, a separate, unrelated identity from any BookID.
This is the core idea a relational database adds on top of a plain spreadsheet: tables can reference each other. Once the course project introduces an Orders table in a later module, each order will reference a specific CustomerID and a specific BookID rather than repeating that customer's or book's full details on every order row. That's what "relational" actually refers to, tables related to each other through shared key values, not just data sitting in rows and columns.
A column that references another table's primary key is called a
foreign key. If a future Orders table includes a
CustomerID column, that column is a foreign key pointing back to Customer's own
CustomerID primary key. SQL Server can enforce this relationship directly: it will refuse to insert an order for a CustomerID that doesn't actually exist in the Customer table, which catches a whole category of data-integrity mistakes before they ever happen, rather than leaving an application to notice a broken reference after the fact.
Each column in a table also has a declared data type, which constrains what kind of value it can hold. Module 1's Inventory table used
NVARCHAR for text,
DECIMAL for money, and
INT for whole numbers, and that choice wasn't arbitrary. A column's data type is a promise the database enforces on every row: a
Price column typed as
DECIMAL physically cannot hold the text "forty dollars," and a database that enforces this catches a bad value the moment it's written, rather than letting it reach a Razor Page and cause a confusing error later.
Common Database Systems
SQL Server 2025, the database this course uses, is one of several widely used relational database systems. Knowing the landscape helps put it in context:
| System | Where It's Commonly Used |
| SQL Server | Microsoft's own database, tightly integrated with .NET and Azure; this course's choice |
| PostgreSQL | Open source, widely used across platforms, popular for its standards compliance and extensibility |
| MySQL | Open source, extremely common in PHP-based and web hosting environments |
| Oracle Database | Common in large enterprises, especially where Oracle's other enterprise software is already in use |
| SQLite | A lightweight, file-based database with no separate server process, common in mobile apps and local development |
All five speak some dialect of SQL, and the table, row, and key concepts above apply to every one of them. What differs between them is mostly in the details: exact syntax, performance characteristics, licensing, and the tooling built around each one. Learning SQL Server 2025 well in this course gives you a foundation that transfers to any of the others with a comparatively small amount of additional learning, since the underlying relational model doesn't change from one system to the next.
Not every database system is relational, either, and it's worth knowing that category exists even though this course doesn't build against it. Document-oriented databases like MongoDB, one of the alternate stacks Module 1, Lesson 2 listed for the course project, store each record as a flexible, self-contained document rather than as a row in a fixed-column table. That trade-off can be useful when records genuinely don't share a consistent shape, but it gives up the relational model's built-in foreign-key enforcement described above. This course sticks with the relational model throughout, both because SQL Server 2025 is this course's chosen database and because the relational model is still the default choice for the kind of structured, interrelated data, customers, books, orders, that VirtualBookShelf represents.
Database Access Solutions: ADO.NET, Entity Framework Core, and ODBC
A database sitting on a server does nothing by itself; something has to connect to it, send it a request, and read back the response. Several technologies exist to do exactly that, and this course uses two of them directly:
- ADO.NET, the .NET data access API this course teaches first. A connection object opens a link to SQL Server 2025 using a connection string, a command object carries the SQL text to run, and a data reader reads the results back row by row. This is the lower-level, explicit approach, and this course's early Razor Pages lessons build on it directly.
- Entity Framework Core, introduced later in the course, an object-relational mapper that lets C# code query and update the database by working with objects, a
Book or a Customer class, rather than writing SQL text by hand. EF Core generates the equivalent SQL underneath, once you already understand what that generated SQL is actually doing thanks to having learned ADO.NET first.
A third technology,
ODBC (Open Database Connectivity), is worth recognizing even though this course doesn't build directly on it. ODBC is a vendor-neutral standard for connecting to a database from any language or tool that implements it, and it's still actively maintained; Microsoft ships current ODBC drivers for SQL Server 2025 today. You'll most often encounter ODBC behind the scenes in reporting tools, business intelligence software, or older applications that predate .NET entirely, connecting to the same SQL Server database your Razor Pages application uses, through a completely different access path. Recognizing that ODBC exists and what role it plays is enough for this course; building against it directly is outside this course's scope.
It's worth being precise about one piece of legacy terminology here, since an older version of this course taught against it directly: classic
ADO (ActiveX Data Objects), accessed through Recordset objects in VBScript, is not the same thing as ADO.NET despite the similar name. Classic ADO was a COM-based technology built for Classic ASP and predates .NET entirely. ADO.NET is a ground-up redesign that happens to share a name with its predecessor; conceptually related, since both exist to move data between an application and a database, but not the same API, and not interchangeable in code. If you ever encounter the term "ADO" in older documentation or an older version of this course's material, it almost certainly means classic ADO, not the ADO.NET this course actually teaches.
What SQL Is, and What It Does
SQL, Structured Query Language, is the language every one of these access technologies ultimately speaks to the database, whether it's ADO.NET sending a command, Entity Framework Core generating one on your behalf, or a reporting tool connecting through ODBC. Underneath ADO.NET's connection and command objects, underneath EF Core's generated queries, underneath ODBC's driver layer, the database itself is only ever asked to do one of four things: create a row, read rows back, update a row, or delete a row, the CRUD operations Module 1 introduced, expressed as
INSERT,
SELECT,
UPDATE, and
DELETE statements.
All four CRUD operations against the Inventory table shown above look like this:
INSERT INTO Inventory (Title, Author, ISBN, Price, QuantityOnHand)
VALUES ('Refactoring', 'Martin Fowler', '9780134757599', 54.99, 5);
SELECT Title, Author, Price FROM Inventory WHERE QuantityOnHand > 0;
UPDATE Inventory SET QuantityOnHand = QuantityOnHand - 1 WHERE BookID = 1;
DELETE FROM Inventory WHERE BookID = 2;
The second statement asks SQL Server for the title, author, and price of every book currently in stock. Whether that request reaches the database through an ADO.NET
SqlCommand, through EF Core translating a LINQ query, or through an ODBC-connected reporting tool, this is fundamentally the same request, written in the same language, asking the same database the same question. SQL doesn't change depending on which access technology sends it; what changes is only how that SQL text gets constructed and how its results get read back into your application.
From Database to Page: Connection Strings and Model Binding
The last two module objectives above describe the two steps that actually get data from SQL Server 2025 onto a rendered Razor Page.
The first step is configuring a connection string, typically stored in `appsettings.json`:
{
"ConnectionStrings": {
"VirtualBookShelf": "Server=localhost;Database=VirtualBookShelfDb;Trusted_Connection=True;TrustServerCertificate=True;"
}
}
This is the modern equivalent of what the legacy version of this course called "inserting a data source into a project": telling the application where its database lives and how to authenticate, once, in a central place, rather than hardcoding that information into every page that needs it.
The second step is getting query results onto the page itself, through Razor Pages model binding and Tag Helpers, introduced in Module 1. A Razor Page's code-behind file runs a query, perhaps the
SELECT statement above, against the connection string configured above, and stores the results in a public property. The page's markup then uses a Tag Helper to turn that property into HTML, an
<li> for each book, a table row for each result, without the page needing any direct knowledge of how the data was fetched. This is what the legacy version of this course called "binding a database to an environment," translated into terms that actually describe how ASP.NET Core Razor Pages works.
A Few Common Questions
Do I need to pick between ADO.NET and Entity Framework Core right now? No. This course deliberately teaches ADO.NET first and EF Core later, in that order, for the reasons Module 1 explained. This lesson only asks you to recognize that both exist and roughly what each one does; you won't write either one until a later module actually walks through it.
If ODBC still works and is vendor-neutral, why doesn't this course just teach that instead? ODBC gives you a common way to connect to many different database systems, but it doesn't give you the strongly typed, object-oriented integration with C# and Razor Pages that ADO.NET and Entity Framework Core do. For an ASP.NET Core application talking to SQL Server specifically, ADO.NET and EF Core are the more natural fit; ODBC earns its place in situations where the same database needs to be reached from tools or languages that don't have their own dedicated .NET-style data access layer.
Is SQL the same across SQL Server, PostgreSQL, MySQL, and the others in the table above? Close, but not identical. All of them implement the core SQL standard, the SELECT, INSERT, UPDATE, and DELETE statements shown above would run with little or no change on any of them, but each system also has its own extensions and quirks beyond that core. SQL Server's IDENTITY columns, for instance, are written differently in PostgreSQL and MySQL, even though the underlying concept, an automatically incrementing primary key, exists in all three.
Why does a table need a primary key at all? Without one, there's no reliable way to refer to exactly one row. Two customers could share the same name; nothing but an ID guarantees uniqueness. Every meaningful operation this course teaches, updating a specific book's quantity, deleting a specific customer, joining Orders to Customer, depends on being able to say "this exact row and no other," and a primary key is what makes that possible.
What's Ahead
The next lesson in this module covers how data is actually stored once it's inside a table: data types, how SQL Server organizes rows and pages on disk, and what that means for the kinds of columns you choose when a table is designed, the same kind of decision already made for Customer and Inventory back in Module 1. Nothing introduced in this lesson needs to be memorized in detail yet; the goal here was to give you a map of the landscape, tables and keys, the systems that host them, the technologies that connect to them, and the language that speaks to them, so each later lesson's deeper dive into one piece of that map has somewhere to attach.
One thing worth carrying forward from this lesson in particular: every concept introduced here, tables, primary and foreign keys, data types, SQL's four CRUD operations, ADO.NET and EF Core as access layers, applies directly to the Customer and Inventory tables you already know from Module 1, Lesson 3. Nothing here is abstract theory waiting for a future example; the example already exists, and the rest of this course is largely about building real pages against it.
