Database systems · Chapter 2 · Data models · Study guide

Chapter 2 review: data models

A short, plain summary of every term you need from Chapter 2. Each entry is a definition and the one or two facts that usually get asked about. The longer worked pages in this section go deeper where a picture helps.

The relational model

Proposed by E. F. Codd in 1970 and still the design almost every business database uses.

Relational model

The relational model represents data as a collection of tables that are linked to one another by shared values rather than by stored pointers. Its foundation is a mathematical idea called a relation, which is a set of rows with no order and no duplicates. The user is not expected to think that way: the RDBMS presents each relation as an ordinary table and hides the storage details, and that simplicity is the reason the model displaced the hierarchical and network designs that came before it.

Relational model = the database structure and rules.

Relational diagram = the picture that shows that structure visually.

Relational model terminology

The same three things have a formal name, a name the user actually says, and an older file system name. The formal terms are worth knowing because they explain the behaviour: rows come back unordered unless you sort them, because a relation is a set.

Three vocabularies for the same three things.
Relational modelWhat the user seesFile system
RelationTableFile
TupleRowRecord
AttributeColumnField

Related terms from the same chapter: a domain is the set of allowed values for an attribute, a primary key is the attribute or attributes that uniquely identify each row, and a foreign key is an attribute in one table whose values must match a primary key in another. Foreign keys are what hold the relationships together.

Schema and subschema

A schema is the description of the whole database: every table, view, and index, and how they relate, defined once. A subschema is the slice of that schema a particular application program is allowed to see and use. The pair comes from the network model, and the idea carried straight into relational systems as views. The schema together with this descriptive information is the database's metadata.

One schema, several subschemas Three application programs on the left each connect to one shared schema on the right. Each program sees only its own subschema, a slice of the whole. Billing app sees: customers, invoices Sales app sees: customers, products Reports app sees: invoices only SCHEMA every table, view and index, defined once CUSTOMER INVOICE PRODUCT PAYMENT a subschema is a window onto this
See the levels of data abstraction page for how the schema, the subschemas above it, and the physical storage below it stay independent of one another.

DBMS, RDBMS, and DDL

The software that manages the database, and the language you use to lay it out.

The difference between a DBMS and an RDBMS

A DBMS, a database management system, is the software between the user and the stored data. It handles storage, access control, security, backup and recovery, and lets many users work at once without seeing the physical layout. Hierarchical and network systems are all DBMSs. An RDBMS, a relational database management system, does everything a DBMS does and adds the relational rules on top: data is held as related tables, integrity is kept through primary and foreign keys, and SQL is the language for defining and querying it. Every RDBMS is a DBMS; the extra letter is the relational rule set.

RDBMS sits inside DBMS A large box labelled DBMS lists the general services. A smaller box inside it labelled RDBMS lists the relational features added on top. DBMS stores data, controls access and security, runs backup and recovery, manages many users at once, hides the physical storage RDBMS all of the above, plus: data held as related tables, integrity kept through primary and foreign keys, SQL as the language Oracle, SQL Server, PostgreSQL, MySQL, Db2

Data definition language (DDL)

The DDL is the part of the database language used to create and change the structure of the database: the schema and subschemas, the tables, the columns and their data types, and the keys and constraints. In SQL the DDL statements are CREATE, ALTER, and DROP. It is the counterpart of the DML, the data manipulation language, which works with the rows inside those structures using SELECT, INSERT, UPDATE, and DELETE. Short version: DDL defines the containers, DML moves the contents.

Diagrams of a design

Three named things that look similar and are easy to mix up, plus the notation they are usually drawn in.

Relational diagram

A relational diagram is a picture of the tables in a relational database together with the primary and foreign keys that link them. It shows each table as a box with its columns listed, marks the keys, and draws a line from each foreign key back to the primary key it references. It is an implementation level drawing: everything on it corresponds to something you could actually build with DDL.

Relational diagram vs the ER model vs an ERD

These three sit at different levels. The entity relationship model is the approach: the set of ideas, introduced by Peter Chen in 1976, for describing data as entities, attributes, and relationships. An ERD is a single diagram that applies that approach to one specific database. A relational diagram is a lower level drawing of the tables and keys that database turns into.

Same design, three views of it.
TermWhat it isCan show M:N directly?
ER modelThe modelling approach and its conceptsYes, as an idea
ERDA conceptual diagram drawn with that approachYes
Relational diagramAn implementation diagram of tables, keys, and linksNo, it needs a bridge table first

For a design as small as one customer and one invoice the ERD and the relational diagram look almost identical, which is why one drawing often serves both. They stop looking alike the moment the design contains a many to many relationship. The customer and invoice page walks through exactly this case.

Crow's Foot notation

Crow's Foot is the most common notation for drawing relationships. Each end of a relationship line carries two marks: the one touching the entity box is the maximum, one or many, and the one set just behind it is the minimum, zero or one. The four resulting symbols are exactly one, zero or one, one or many, and zero or many. Connectivity, whether the relationship is 1:1, 1:M, or M:N, comes only from the two maximums.

The four Crow's Foot end symbols From left to right: exactly one, zero or one, one or many, zero or many. exactly one zero or one one or many zero or many
The full walkthrough, with an interactive builder, is on the reading Crow's Foot notation page.

Business rules and the ER building blocks

Where the model comes from, and the four words the model is built out of.

Business rules and constraints

A business rule is a brief, precise, unambiguous statement of a policy or practice in the organization, written plainly enough to design from. Rules are gathered from managers, written procedures, and interviews with the people who do the work. They matter because they tell the designer what the data means and how it behaves, and they translate mechanically into the model: nouns tend to become entities, verbs tend to become relationships, and quantities and limits become constraints. A constraint is a restriction on the data that the database enforces, such as a value that may not be null, must be unique, or must fall in a range. Constraints are how business rules are kept true once the database is running.

Entity, entity instance, entity set, attribute, relationship

These are the parts of an ER model, and the exam question is usually which is which.

The four building blocks, plus the term for one occurrence.
TermWhat it isIn table terms
EntityA person, place, thing, or event data is kept about; drawn as a rectangle, named with a singular nounA table
Entity instanceOne single occurrence of that entity, such as one particular customerOne row
Entity setThe whole collection of instances of one entityAll the rows of the table
AttributeA characteristic of an entityA column
RelationshipA named association between entities, read in both directions with a verb phraseA foreign key link
Entity, attribute, relationship, entity set, and instance A CUSTOMER entity box listing three attributes is joined by a relationship line to an INVOICE entity box. One row of the customer table is one entity instance; all the rows together are the entity set. CUSTOMER customer_id last_name phone each line is an attribute is billed on the line is the relationship INVOICE invoice_id customer_id invoice_total the box is the entity and its whole entity set · one row of it is one entity instance

The object oriented model

A later model that keeps data and the code that acts on it together in one place.

The difference between an object, a class, and a method

An object is a representation of one real world thing, holding both its data and its behaviour, for example one specific customer. A class is the template for a group of objects that share the same structure and behaviour; every object is an instance of some class. A method is a piece of code defined in the class that performs an action on an object's data, such as place order or pay. You run a method by sending the object a message. The class also lists the object's attributes, so a class is really attributes plus methods.

A class and two of its objects A Customer class box with an attributes compartment and a methods compartment. Two object boxes below are labelled as instances of the class. Customer (class) attributes: name, phone, balance methods: place_order(), pay(), close() a method is code that acts on the object's data objects are instances of the class object: Reyes, balance 0 one real customer object: Chandra, balance 42 another real customer

Inheritance and UML

Inheritance is the ability of a class to take on the attributes and methods of a class above it in a hierarchy. A general class such as Person holds what is common; more specific classes such as Employee and Customer inherit that and add their own. It saves repetition and keeps shared behaviour in one place. UML, the Unified Modeling Language, is a standard set of diagrams and symbols, based on object oriented ideas, for modelling a system. Its class diagram shows classes, their attributes and methods, and the relationships and inheritance between them, so it is often used to draw a data design even outside pure object oriented work.

Inheritance in a UML class diagram A Person class at the top. Employee and Customer classes below connect up to it with hollow triangle arrows, showing that they inherit the name and address attributes and add their own. Person name, address Employee and Customer inherit name and address Employee adds salary, hire_date Customer adds balance, credit_limit
The hollow triangle always points at the more general class. This is the same notation Chapter 2 uses to compare Crow's Foot with UML.

Big Data, Hadoop, and MapReduce

The end of the chapter, on data that does not fit the relational model comfortably and the tools built for it.

Big Data and the 3 Vs

Big Data is the effort to store and get value from volumes of data, much of it generated on the web, that are too large and too fast moving for a traditional relational database to handle at reasonable cost. It is usually characterized by three properties, the 3 Vs.

The three Vs of Big Data Volume is how much data there is. Velocity is how fast it arrives and must be dealt with. Variety is how many different formats it comes in. Volume how much data terabytes to petabytes, too big for one server Velocity how fast it moves streaming in constantly, often needs a quick answer Variety how many formats tables, text, log files, images, video, sensor feeds
Some writers add more Vs such as veracity and value, but Chapter 2 defines Big Data by these three.

Hadoop, HDFS, and the NameNode

Hadoop is an open source, Java based framework for storing and processing very large data sets across a cluster of ordinary, low cost machines, designed so that the failure of any one machine does not lose data or stop the job. Its two main parts are a storage layer, HDFS, and a processing layer, MapReduce.

HDFS, the Hadoop Distributed File System, splits each file into large blocks and spreads copies of every block, three by default, across the machines in the cluster. It follows a write once, read many pattern. The cluster has two kinds of node. The NameNode is the master: it holds only the metadata, meaning the directory structure and the record of which block lives on which machine, but none of the file contents. The DataNodes are the workers: they hold the actual blocks and serve them to clients. A client asks the NameNode where a file's blocks are, then reads or writes them straight from the DataNodes.

HDFS: one NameNode, many DataNodes A client first asks the NameNode where a file's blocks are. The NameNode returns metadata only. The client then reads and writes the blocks directly from the DataNodes, each of which stores several blocks, replicated across the cluster. Client runs the job NameNode metadata only: file names, block list, which node holds each block 1. where are the blocks? DataNode block A, block C DataNode block A, block B DataNode block B, block C every block is stored on three nodes 2. transfer blocks straight from the DataNodes
Because the NameNode is the only place the block map lives, it is the single point whose loss would matter most, which is why real clusters keep a standby copy of it.

MapReduce

MapReduce is the processing model Hadoop uses to run a computation over data that is spread across many machines. It has two phases. The map phase runs on each machine in parallel, close to the data it already holds, and turns its slice of the input into key and value pairs. The pairs are then shuffled and sorted so that all values for the same key end up together. The reduce phase takes each key and its collected values and combines them into the final result, for example a count or a total per key.

MapReduce in two phases Input is split across nodes. The map phase turns each split into key and value pairs in parallel. The pairs are shuffled and sorted so equal keys meet. The reduce phase aggregates each key's values into the output. Input split by block Map parallel, emits (key, value) Shuffle and sort group equal keys Reduce aggregate per key Output
Word count is the standard example: map emits (word, 1) for every word, and reduce adds up the 1s for each word.