Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Database Design and Modeling with PostgreSQL and MySQL

You're reading from   Database Design and Modeling with PostgreSQL and MySQL Build efficient and scalable databases for modern applications using open source databases

Arrow left icon
Product type Paperback
Published in Jul 2024
Publisher Packt
ISBN-13 9781803233475
Length 222 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Alkin Tezuysal Alkin Tezuysal
Author Profile Icon Alkin Tezuysal
Alkin Tezuysal
Ibrar Ahmed Ibrar Ahmed
Author Profile Icon Ibrar Ahmed
Ibrar Ahmed
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Part 1: Introduction to Databases
2. Chapter 1: SQL and NoSQL Databases: Characteristics, Design, and Trade-Offs FREE CHAPTER 3. Chapter 2: Building a Strong Foundation for Database Design 4. Part 2: Practical Implementation
5. Chapter 3: Getting Your Hands Dirty with PostgreSQL and MySQL 6. Part 3: Core Concepts in Database Design
7. Chapter 4: Mastering the Building Blocks of Database Design and Modeling 8. Part 4: Advanced Database Techniques
9. Chapter 5: Advanced Techniques for Advanced Databases 10. Chapter 6: Understanding Database Scalability 11. Part 5: Best Practices and Future Trends
12. Chapter 7: Best Practices for Building and Maintaining Your Database 13. Chapter 8: The Future of Databases and Their Designs 14. Index 15. Other Books You May Enjoy

Exploring the relational data model (SQL databases)

The relational data model is the foundation of SQL databases and has been widely used in the industry for several decades. It is based on the principles of set theory and logic, providing a structured and organized way to store and retrieve data. In this model, data is organized into tables, each representing an entity, and relationships between entities are established through keys.

As we focus on the relational paradigm, it’s essential to recognize that other data models that have emerged in the digital era will still be using this foundation.

Tables, rows, and columns

In the relational data model, data is stored in tables, which are two-dimensional structures consisting of rows and columns. Each row in a table represents a record or an individual data entry, while each column represents an attribute or property of the data.

For example, consider a table named Customers in a database for an e-commerce application. Each row in the table represents a customer, and the columns may include attributes such as customer ID, name, email address, and date of birth.

Keys

Keys are essential components of the relational data model as they can establish relationships between different tables and ensure data integrity:

  • Primary key: It is recommended to have a primary key in a relational database as this acts as a unique identifier for each row in the table. It ensures that each record is distinct and can be referenced uniquely. The primary key enforces the entity’s integrity and allows for efficient retrieval of specific records.
  • Foreign key: A foreign key comprises a column or group of columns within a tale, which points to the primary key of another table. It establishes a relationship between two tables, representing a one-to-many or many-to-many association. Foreign keys ensure referential integrity, meaning that the relationships between entities remain consistent and valid.

For example, in the Customers table, the customer ID column may serve as the primary key, uniquely identifying each customer. If there is another table named Orders, the customer ID column in the Orders table can be a foreign key that references the customer ID in the Customers table, indicating which customer placed each order.

Normalization

Normalization is an essential concept in the relational data model that aims to reduce data redundancy and improve data integrity. It involves organizing data into multiple tables and ensuring that each piece of information is stored in only one place. Normalization helps to eliminate data anomalies, such as update anomalies (inconsistent data) and insertion anomalies (inability to add data).

There are different normal forms, ranging from First Normal Form (1NF) to higher normal forms (for example, Second Normal Form (2NF), Third Normal Form (3NF), and others), each with specific criteria for data organization.

Building on this foundation of data organization, let’s move into the world of the most common language of all databases: SQL.

Structured Query Language (SQL)

One of the most significant advantages of using SQL databases is the powerful querying capabilities provided by SQL. SQL is a standardized language that’s used to interact with relational databases, allowing developers to perform various operations on data, such as retrieving, inserting, updating, and deleting records.

SQL provides a straightforward and efficient way to write complex queries and retrieve specific information from the database. The use of SQL enables developers to access data without worrying about the underlying data storage and its organization as the database management system handles these complexities internally.

Beyond the capabilities of SQL, transactional support is crucial for many businesses and applications.

ACID transactions

SQL databases stand out for their unwavering support of ACID transactions, offering a foundation of reliability, isolation, and consistency for database operations, even amid failures. Let’s take a closer look at each ACID component:

  • Atomicity ensures transactions are all-or-nothing operations. This means every transaction is treated as a single unit, which either completes entirely or not at all. Should any part of a transaction fail, the entire operation is reversed, returning the database to its prior state.
  • Consistency guarantees that every transaction transforms the database from one valid state into another while adhering to all predefined rules and integrity constraints. This ensures the database remains accurate and reliable, both before and after transactions.
  • Isolation means that transactions are executed independently, shielding ongoing operations from the intermediate stages of other transactions. This isolation is managed through varying levels, each balancing the trade-off between data integrity and performance. For instance, “Read Uncommitted” allows visibility of uncommitted changes, increasing speed at the risk of “dirty reads.” Conversely, “Serializable” offers the highest level of isolation, preventing dirty reads, non-repeatable reads, and phantom reads but may introduce performance trade-offs.
  • Durability ensures the permanence of a transaction’s effects once committed. This means that regardless of system failures, such as power outages or crashes, the changes that are made by transactions are preserved and recoverable.

Together, these ACID properties make SQL databases a robust and reliable choice for applications requiring stringent data integrity and consistency. SQL databases, with their commitment to ACID principles, are ideally suited for scenarios demanding reliable and consistent data handling. This reliability is a cornerstone for applications that cannot afford data anomalies or inconsistencies.

In contrast, NoSQL databases pursue a different set of objectives, often prioritizing scalability and flexibility over strict adherence to ACID properties. This makes them suitable for applications with different requirements, such as handling large volumes of unstructured data or requiring rapid scalability.

You have been reading a chapter from
Database Design and Modeling with PostgreSQL and MySQL
Published in: Jul 2024
Publisher: Packt
ISBN-13: 9781803233475
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £16.99/month. Cancel anytime