Software & Apps Apps Defining a Database Domain Data domains enforce data-entry standards on specific database fields Share Pin Email Print Hero Images / Getty Images Apps Best Apps By Mike Chapple Writer Former Lifewire writer Mike Chapple is an IT professional with more than 10 years' experience cybersecurity and extensive knowledge of SQL and database management. our editorial process Twitter Mike Chapple Updated January 04, 2020 26 26 people found this article helpful A database domain, at its simplest, is the data type used by a column in a database. This data type can be a built-in type (such as an integer or a string) or a custom type that defines constraints on the data. Every type of database provides a way to define a set of restrictions and rules that govern allowable data, even if it does not call it a domain. See your database’s documentation for details. Data Entry and Domains When you enter data into an online form of any kind—whether it's just your name and email, or a complete job application—a database stores your input behind the scenes. That database evaluates your entries based on a set of criteria. For example, if you enter a ZIP code, the database expects to find five numbers, or for a complete U.S. ZIP code: five numbers followed by a hyphen, and then four numbers. If you enter your name into a zip code field, the database will likely complain. That’s because the database is testing your entry against the domain defined for the zip code field. A domain is basically a data type that can include optional restrictions. Understanding a Database Domain To understand a database domain, let’s consider a few other aspects of a database: A database schema defines a set of attributes, also called columns or fields. A table called Employee Contact Informationt may include attributes for FirstName, LastName, JobTitle, StreetAddress, City, State, ZipCode, PhoneNumber, and Email.Each attribute incorporates a domain that defines allowable values potentially including its data type, length, values, and other details. For example, the domain for an attribute ZipCode might specify a numeric data type, such as an integer, usually called an INT or an INTEGER, depending on the database. Or a database designer might choose to define it instead as a character, usually called a CHAR. The attribute can be further defined to require a specific length, or whether an empty or unknown value is allowed. When you gather together all the elements that define a domain, you end up with a customized data type, also called a “user-defined data type” or a UDT. About Domain Integrity The allowed values of an attribute establish domain integrity, which ensures that all data in a field contains valid values. Domain integrity is defined by: The data type—such as integer, character, or decimal.The allowed length of the data.The range, defining the upper and lower boundaries.Any constraints, or limitations on allowable values. For example, a U.S. ZIP code field might enforce a complete ZIP+4 code or a full nine-digit code.The type of NULL support—or whether an attribute can have an unknown, or NULL value.The default value, if any.The date format painter, if applicable (for instance, dd/mm/yy or mm/dd/yyyy). Creating a Domain For databases that use Structured Query Language or a flavor of SQL, use the CREATE DOMAIN SQL command. Almost Every Web Page You Visit Has SQL Behind It For example, the execution statement here creates a ZipCode attribute of data type CHAR with five characters. A NULL, or unknown value, is not allowed. The range of the data must fall between “00000” and “99999.” That creates a ZipCode attribute of data type CHAR with five characters. A NULL, or unknown value, is not allowed. The range of the data must fall between “00000” and “99999.” CREATE DOMAIN ZipCode CHAR(5) NOT NULL CHECK (VALUE >= '00000' AND VALUE <= '99999') These database constraints will push an error to an application that serves as the front-end to your database when the constraint is violated, so program an error-capture subroutine into your program to sanity-check before the program thinks it's properly added information to the database.