Domain in DBMS

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.
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
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:
-
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:
-
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.