Datasheet

The following sections examine tables; relationships; an important property of relational databases that
emerges from these constraints — normalization; and one of the underlying mechanisms by which all
this is achieved: keys.
Tables
Characteristically, an RDBMS splits the data stored in a database into multiple locations, each of which
contains a specific set of data. These locations are called tables. A table contains multiple rows, each of
which is defined in multiple columns (also known as records and fields).
Phone book data, for example, could be stored in a single table, where each row is a single entry contain-
ing columns for name, phone number, and address. Tables are defined such that every row they contain
includes exactly the same columns — you can’t include additional columns for a given row just because
you feel like it. Columns are also assigned specific data types to restrict the data that they can contain.
In this example all the data types are strings, although more space might be allocated to address fields
because addresses typically consist of more data than names. You might decide to include an additional
Boolean column in a phone book table, however, which would say whether the record was an individual
or an organization. Other tables might include numeric columns, columns for binary data such as images or
audio data, and so on. In addition, a table can specify whether individual columns must contain data, or
whether they can contain null values (that is, not contain values).
Each table in a database has a name to describe what it contains. There are many conventions used for
naming tables, but the one used in this book is to use singular names, so for a phone book table you’d
use
PhoneBookEntry for the name rather than PhoneBookEntries.
The name and structure of tables within a database, along with the specification of other objects
that databases may contain and the relationships between these objects, are known as the schema
of the database.
The word “object” is used here with caution — but correctly. Relational databases can contain many
types of objects (including tables), as you will see throughout this book, but that doesn’t make them
object-oriented. This distinction will be made clearer in the section on OODBMSes shortly.
Figure 1-1 shows the supposed
PhoneBookEntry table graphically, by listing column names and data
types, and whether null values are permitted.
Figure 1-1: The PhoneBookEntry table
The diagram for the
PhoneBookEntry table shows data types as used in SQL Server, where some data
types also include lengths. Here, the
EntryName field is a string of up to 250 characters, PhoneNumber is
a string of up to 50 characters,
Address is a string with no defined maximum size, and IsIndividual is
a
bit (0 or 1), which is the SQL Server type used for Boolean data.
4
Chapter 1
44063c01.qxd:WroxBeg 9/12/06 10:30 PM Page 4