Chapter 10. Flexible and Schemaless

One of the strengths of relational databases is their ability to enforce data structures. You constrain data in a relational database by defining tables and defining columns within those tables that enforce basic data types like strings, dates, and numbers, and then define relationships between tables. SQL, as the lingua franca of relational databases, is by extension a tool for transforming this well-structured relatable data into a format digestible by applications. In the early days of relational databases, data types were simple and people looked to relational databases for structure. This started to change with the advent of SQL:1999. The big leap in SQL:1999 was that types need not be just primitives, but could also be composites of primitives. This allowed table columns to store arrays, nested tables, and even user-defined types. Specialized data types sprung up to support networks, encryption, full text search, geospatial applications, and much more.

A relational database is not the only way to organize data, however. Here are some alternatives to the relational model, often referred to as NoSQL or not-only-SQL databases:

Key/value stores
Data is stored as a set of key/value pairs, where the key acts as a unique identifier. Support is often limited to retrieval, insertion, modification, and deletion.
Document stores
This is similar to a filesystem. Each document (record) is a complex object in its own right. The storage format is often ...

Get SQL in a Nutshell, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.