'What is the difference between check and domain constraint in database?
I am studying relational database. While reading about the constraint the domain constraint and check seemed similar to me. What are the exact differences between them?
Solution 1:[1]
Domain constraints are a user-defined data type which is a definition of a valid set of values for an attribute and we can define them like this: Domain Constraint = data type + Constraints (NOT NULL / CHECK / DEFAULT)
As you can see CHECK is one of the ways in which a domain constraint can be applied.
For Example: Let's say, I have a table called student_info and I want to add a field called stu_id whose value should always be greater than 100, then the domain constraint will look like this
create domain id_value int
constraint id_test
check(value > 100);
create table student_info (
stu_id id_value PRIMARY KEY,
stu_name varchar(30),
stu_age int
);
Here id_value is of type int and has a constraint to check if the value is greater than 100 or not.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
