Overview

10 Relational Databases

This chapter introduces how to modernize Banning Books’ ordering system with a cloud-hosted relational database. It explains why relational databases are a strong fit for structured, transactional workloads and highlights the business priorities that guide all choices: performance, cost, disaster recovery, and security. The narrative frames database work as equal parts good design and sound platform selection, emphasizing schema planning, thoughtful normalization and denormalization, and the advantages of running managed databases on Azure for global access and operational reliability.

The chapter walks through a pragmatic schema for customers, orders, order items, books, reviews, and categories, showing how keys and relationships capture business processes and enable scalable queries. It then compares Azure SQL Database, Azure Database for MySQL, and Azure Database for PostgreSQL, outlining their strengths, trade-offs, and cost considerations. While each service can meet core needs, Azure SQL Database is selected for its blend of performance features, built-in security, and disaster recovery options, with step-by-step Azure CLI examples for provisioning and configuring databases.

Operational excellence is addressed through performance tuning (automatic tuning for indexes and plans, query performance insights, and partitioning strategies), and elastic scale patterns (vertical scaling with tiers/DTUs or vCores, and horizontal scaling via read replicas). A robust resilience posture is built from automated backups, geo-replication, and failover groups for coordinated, low-downtime failovers. Security guidance covers Entra ID–based authentication and RBAC, encryption at rest with TDE, encryption in transit via TLS, and strict least-privilege access. The chapter closes with practical cost hygiene, reminding readers to clean up resources to avoid unnecessary spend.

The Customers and Orders tables are related using the Id in the Customers table.
Denormalizing the Posts table by adding the count of comments on each post.
Banning books ordering database schema showing the relationships between tables.
The Azure relational database selection represented as Banning Books.
Azure SQL automatic tuning.
Partitioning a table in a database can improve performance dramatically if done correctly.
Poster for Banned Books Week sales and Ultra Black Friday
Vertical scaling is increasing the size of CPU and memory for the same VM.
Horizontal scaling of a SQL instance means adding more instances as demand increases and remove them again as demand decreases.
Geo-replication of the database between two regions means the Banning Books website can withstand disaster.
A failover groups abstracts away the need to know which is the primary and secondary database server.
The principle of least privilege means that user roles can only access resources necessary to carry out their work.

Summary

  • The database schema defines the structure of the data, the relationships between that data, and how we access the data.
  • The schema provides a framework for storing and retrieving data in a structured and organized manner and is an essential step in any relational database.
  • Normalization is the process of organizing data in a way that minimizes redundancy and ensures that each piece of data is stored in only one place.
  • Denormalization is the process of intentionally introducing redundancy into a database schema to improve performance.
  • There are pros and cons to both normalization and denormalization, such as data redundancy, performance, scalability, maintenance and flexibility. You need to consider these in each scenario where you have to decide on your approach.
  • Azure Database for MySQL is a fully managed service that brings the extensive capabilities of the widely-used open-source MySQL database system to the Azure cloud platform.
  • Azure PosgreSQL is a managed service on Azure, and is known for its robustness, advanced features, and strong standards compliance, making it a popular choice for complex, high-scale applications.
  • Automatic tuning analyzes your database workload and provides recommendations for creating and dropping indexes.
  • Automatic tuning has three options: force plan, create index and drop index. These automatic tuning options can be enabled or disabled individually, giving you the flexibility to choose the level of automatic tuning that's right for your database.
  • Partitioning is a technique used to divide a large database table into smaller, more manageable pieces, while maintaining the abstraction of a single table to the user.
  • Vertical scaling means increasing or decreasing the compute size and/or memory of your database server.
  • Horizontal scaling, or scaling out, involves adding more replicas of your database to distribute the load at peak times.
  • Geo-replication in Azure SQL Database is a feature that allows you to replicate your databases to a secondary server located in a different geographic region.
  • Failover groups in Azure SQL Database are an abstraction built on top of geo-replication, designed to facilitate database failover in a more automated and coordinated manner across multiple databases.
  • The principle of least privilege dictates that users and applications should be granted only the minimum levels of access—or permissions—necessary to perform their functions.

FAQ

What are the key goals for Banning Books’ ordering system when using a relational database on Azure?Performance, cost, disaster recovery, and security. The system must handle high traffic with fast response times, stay affordable through options like serverless and reserved capacity, survive outages with backups and geo-replication, and protect data via encryption, access control, and auditing.
How do normalization and denormalization differ, and when should I use each?Normalization reduces redundancy and improves integrity by splitting data into related tables (great for consistent writes and storage efficiency). Denormalization intentionally duplicates data to simplify queries and boost read/write performance for specific workloads. Most production schemas blend both approaches to balance integrity and speed.
What does the Banning Books relational schema look like?Core tables include Customers, Orders, Order_Items, Books, Reviews, and Categories. Relationships are primarily one-to-many (for example, one Customer to many Orders; one Book to many Reviews). Order_Items links Orders and Books, and Books links to Categories; foreign keys enforce these relationships.
How do I create an Azure SQL Database and apply the Banning Books schema?Create the server and database, then run the CREATE TABLE statements. Example (Azure CLI): az sql server create --name BanningBooksServer --resource-group BanningRG --location australiaeast --admin-user banningadmin --admin-password <password> and az sql db create --resource-group BanningRG --server BanningBooksServer --name BanningBooksDB --service-objective Basic. Connect with Azure Data Studio and execute the schema SQL to create tables and foreign keys.
How should I choose between Azure SQL Database, Azure Database for MySQL, and Azure Database for PostgreSQL?Pick Azure SQL for tight Azure integration, strong managed features, and advanced security/DR—often best for this scenario. Choose MySQL if you need native MySQL compatibility and tooling with generally lower base cost (some DR/security features require more setup). Choose PostgreSQL for advanced SQL features and robustness, accepting that active geo-replication isn’t available and some features may require tuning.
What built-in performance tuning options does Azure SQL provide?Automatic tuning can force last good plans, create useful indexes, and drop redundant ones. Use Query Performance Insight to find top resource-consuming queries and fix them (for example, by indexing JOIN/WHERE columns or improving query patterns). Together, these features streamline tuning while minimizing risk to live workloads.
When and how should I use partitioning?Use partitioning on very large tables to improve query speed, maintenance, and archival (for example, partition Books by publication year or Orders by order date). Queries that filter on the partition key scan fewer pages, and maintenance can target individual partitions. Plan partition keys around common filters and data lifecycle.
How can I scale the database for traffic spikes?Scale up (vertical) by increasing the compute tier or DTUs/vCores, and scale out (horizontal) by offloading reads to replicas. For DTU-based tiers you can change the service objective (for example, az sql db update --service-objective S3). Consider read replicas for browse-heavy workloads and use auto-scaling/serverless options where appropriate to control cost.
What disaster recovery features should I enable?Rely on automatic full/differential/log backups for point-in-time restore, then add geo-replication to a secondary region for low-latency reads and failover. For streamlined continuity, configure a failover group to automate failover and expose stable read-write/read-only endpoints. Test restores and failovers regularly.
What security practices are recommended for the database?Use Microsoft Entra ID for authentication and RBAC, enable Transparent Data Encryption (TDE) for data at rest, enforce TLS 1.2+ for data in transit, and follow the principle of least privilege for roles and users. Audit access, apply firewall/private access controls, and review threat protection alerts. Keep secrets out of code and rotate credentials regularly.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Microsoft Azure in Action ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Microsoft Azure in Action ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Microsoft Azure in Action ebook for free