Discussion: more about domains

You learned earlier that a domain is the set of legal values that can be assigned to an attribute. Each attribute in a database must have a well-defined domain; you can’t mix values from different domains in the same attribute. (See below for some examples.) One goal of database developers is to provide data integrity, part of which means insuring that the value entered in each field of a table is consistent with its attribute domain. Sometimes we can devise a validation rule to separate good from bad data; sometimes we can’t. Before you design the data type and input format for an attribute, you have to understand the characteristics of its domain.

General domains

Some domains can only be described with a general statement of what they contain. These are difficult or impossible to analyze precisely; the best we can do is to make them VARCHAR strings that are long enough to hold any expected value. The examples listed below provide more context for these domains.

Domains with a pattern

Some domains have at least some pattern in their permitted values. These might be recognizable in code, for example with a regular expression, although it is still impossible to insure that every value that passes a validity check is actually correct. The examples listed below include three well-known attributes with domains that have such patterns.

Domains with a precise pattern

Few domains conform to a precise pattern that can be analyzed or specified exactly. Two examples follow.

Definitely NOT international postal codes or phone numbers. Don’t ever over-specify a domain or data entry field in any way that would prevent users from entering a valid real-life domain value.

Other domains

Consult DBMS documentation

While there is a SQL standard defined, DBMS vendors deviate from it. Thus, database developers must consult the DBMS vendor documentation to learn about the data types supported in the product being used. Wherever possible, data types supported across multiple vendors should be used as that makes the database more portable.