Domain in DBMS

Learn via video course
FREE
View all courses
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
Topics Covered

The data type defined for a column in a database is called a database domain. This data type can either be a built-in type (such as an integer or a string) or a custom type that defines data constraints.

To understand this more effectively, let's think like this:
A database schema has a set of attributes, also called columns or fields, that define the database. Each attribute has a domain that specifies the types of values that can be used, as well as other information such as data type, length, and values.

Creating a Domain

To create a domain, we use the CREATE DOMAIN command in SQL.

Let's look at the syntax:

The above statement, for example, creates a C_Number attribute with ten integers to store contact numbers. It's not possible to use a NULL or an unknown value. This generates a ten-integer C_Number property, in which it wouldn't be possible to use a NULL or an unknown value.

Domain Integrity Constraints

Domain Constraints are user-defined columns that assist the user in entering values that are appropriate for the data type. If it detects an incorrect input, it informs the user that the column is not properly filled. Or, to put it another way, it's an attribute that describes all of the potential values for the attribute, such as integer, character, date, time, string, and so on.

To read more about domain integrity constraints, please head over to our dedicated article here!

Types of Domain Constraints

There are two types of domain constraints:

  1. NOT NULL:
    The Not Null constraint prevents a column from accepting null values. This implies that you can't create a new record or change an existing one without first putting a value in the field.

    Example:

  2. Check:
    It restricts the value of a column across ranges. It can also be understood as it's like a condition or filter checking before saving data into a column since it defines a condition that each row must satisfy.

    Example:

Conclusion

  • In a database, a domain is a set of values that can be assigned to an attribute.
  • A domain can be created using the CREATE DOMAIN command in SQL.
  • There are two types of domain constraints, NOT NULL and CHECK.