Attributes-Entities   «Prev  Next»

Lesson 6 Attribute domains
Objective Describe Attribute Domains and Domain Types

Describe Attribute Domains

Question: What is meant by the statement "each attribute of an entity contains a domain" in database design?
In database design, when we say "each attribute of an entity contains a domain," we mean that each attribute (also known as a column or field) in a table or entity is associated with a specific set of allowed values called a domain. A domain defines the type of data an attribute can hold and any constraints or rules governing the data. Here are some aspects of domains in database design:
  1. Data type: Domains define the data type of an attribute, such as integers, floating-point numbers, strings, dates, or boolean values. This ensures that only data of the correct type is stored in each attribute.
  2. Constraints: Domains can also include constraints or rules that further restrict the allowed values for an attribute. For exa mple, a domain could specify that an integer attribute must be a positive number, or a string attribute must have a maximum length.
  3. Uniqueness: Domains can enforce uniqueness constraints, ensuring that no two rows in a table have the same value for a specific attribute. This is commonly used for primary keys, which uniquely identify each row in a table.
  4. Referential integrity: Domains can be used to enforce referential integrity by defining foreign key relationships between tables. This ensures that the values in the foreign key attribute must match the values in the referenced primary key attribute, maintaining data consistency across related tables.
  5. Default values: Domains can specify default values for an attribute, which are used when a new row is inserted into the table without a value provided for that attribute.
  6. Validation rules: Domains can define custom validation rules to ensure that the data stored in an attribute meets specific business requirements or rules.
The statement "each attribute of an entity contains a domain" in database design means that each attribute is associated with a specific set of allowed values that define the type of data, constraints, and rules governing the data. Domains help maintain data consistency, integrity, and accuracy in a database.

Domain Data Types

Every attribute has a domain. A domain determines the type of data values that are permitted for that attribute, and thus serves as an attribute constraint. Attribute domains can be very large (long company names, for example), or very short such as the single-letter abbreviations, for example
S, M, L
can be used to indicate clothing sizes).
SQL provides a number of domain types to assign to attributes. The standard domain types include data values for
  1. characters,
  2. numerals,
  3. currency,
  4. dates,
  5. times, and
  6. Boolean entries (a logical value of either true or false).

Most RDBMSs also accept the BLOB (binary large object) domain type, which stores binary objects such as graphics.

Choosing Correct Domain Type

Choosing the correct domain type is critical to the accuracy of a database.
It is important to choose the right domain type for an attribute. For example, zip codes appear as numbers to us, so there is the temptation to attach the numerical domain to them. However, zip codes in the northeastern section of the United States begin with a zero. This would pose problems in a database since the numerical domain drops leading zeros.
Do not think of time periods, such as “1st Quarter Profits,” “2nd Quarter Profits,” as distinct entities.
Instead, create an entity called 'Profits' and use attributes with the date domain to distinguish time periods.

Enforcing domains

The RDBMS uses domain constraints[1] to enforce attribute domains. When a user enters a data value, the RDBMS checks to verify that the domain assigned to that attribute permits that value.
For example, if a user entered letters into a field with a currency domain, that data entry would be rejected. Likewise, a domain that accepted only dates would reject non-date entries. Additionally, most RDBMSs reject impossible dates, such as February 30th.
The next lesson explains the problem with multi-valued attributes.

Attribute Domains Database - Exercise

Before moving on to the next lesson, click the Exercise link below to test your understanding of domains.
Attribute Domains Database - Exercise

[1] domain constraints: Rules that require values of attributes to come from specific domains (e.g., text, numbers, date, etc.).