A database stores application data in an organized way. The application then issues queries to retrieve specific portions of the data as they are needed. The most commonly used databases for web applications are those based on the relational model, also called SQL databases in reference to the Structured Query Language they use. But in recent years document-oriented and key-value databases, informally known together as NoSQL databases, have become popular alternatives.
Relational databases store data in tables, which model the different entities in the application’s domain. For example, a database for an order management application will likely have
A table has a fixed number of columns and a variable number of rows. The columns define the data attributes of the entity represented by the table. For example, a
customers table will have columns such as
phone, and so on. Each row in a table defines an actual data element that assigns values to some or all the columns.
Tables have a special column called the primary key, which holds a unique identifier for each row stored in the table. Tables can also have columns called foreign keys, which reference the primary key of a row in the same or another table. These links between rows are called relationships and are the foundation of the relational database model.
Figure 5-1 shows a diagram of a simple database with two tables that store users and ...