How To Software Defining a Database Domain Ensure Your Data's Integrity Share Pin Email Print Mina De La O/Stone/Getty Images Software Databases Documents Spreadsheets Presentations Desktop Publishing Graphic Design Animation & Video by Mike Chapple An IT professional with more than 10 years of experience in the fields of databases and cybersecurity. Updated November 12, 2018 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. 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. For example, if you have a table “Employee Contact Information,” it might include attributes for FirstName, LastName, JobTitle, StreetAddress, City, State, ZipCode, PhoneNumber, and Email.Each attribute has a domain that defines allowable values. This could include 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 create 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, if applicable (for instance, dd/mm/yy or mm/dd/yyyy). Creating a Domain For databases that use SQL (Structured Query Language) or a flavor of SQL, use the CREATE DOMAIN SQL command. 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 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. Continue Reading