Datasheet

19
Chapter 1: Relational Database Fundamentals
Schemas, domains, and constraints
A database is more than a collection of tables. Additional structures, on
several levels, help to maintain the data’s integrity. A database’s schema
provides an overall organization to the tables. The domain of a table column
tells you what values you may store in the column. You can apply constraints
to a database table to prevent anyone (including yourself) from storing invalid
data in the table.
Schemas
The structure of an entire database is its schema, or conceptual view. This
structure is sometimes also called the complete logical view of the database.
The schema is metadata — as such, it’s part of the database. The metadata
itself, which describes the database’s structure, is stored in tables that are
just like the tables that store the regular data. Even metadata is data; that’s
the beauty of it.
Domains
An attribute of a relation (that is, a column of a table) can assume some finite
number of values. The set of all such values is the domain of the attribute.
Say, for example, that you’re an automobile dealer who handles the newly
introduced Curarri GT 4000 sports coupe. You keep track of the cars you
have in stock in a database table that you name INVENTORY. You name one
of the table columns Color, which holds the exterior color of each car. The
GT 4000 comes in only four colors: blazing crimson, midnight black, snowflake
white, and metallic gray. Those four colors are the domain of the Color
attribute.
Constraints
Constraints are an important, although often overlooked, component of a
database. Constraints are rules that determine what values the table attributes
can assume.
By applying tight constraints to a column, you can prevent people from
entering invalid data into that column. Of course, every value that is legitimately
in the domain of the column must satisfy all the column’s constraints. As I
mention in the preceding section, a column’s domain is the set of all values
that the column can contain. A constraint is a restriction on what a column
may contain. The characteristics of a table column, plus the constraints
that apply to that column, determine the column’s domain. By applying
constraints, you can prevent users from entering data into a column that falls
outside the column’s domain.