Domain Constraints in DBMS
Domain constraints
In this article, we will learn about Domain Constraints in DBMS. It makes sure that the data value entered for that particular column matches with the data type defined for that column . SO, lets discuss domain constraints in detail.
DOMAIN CONSTRAINTS IN DBMS
- DBMS table is viewed as a combination of rows and columns.
For example, if you are having a column called month and you want only [Jan, Feb, March….dec] as values allowed to be entered for that particular column which is referred to as domain for that particular column.
Or For Example, in the age column, it must only accept students greater than 18 age or roll number should be a positive number.
Definition :
Domain constraint ensures two things
- It makes sure that the data value entered for that particular column matches with the data type defined for that column
- It shows that the constraints((NOT NULL / UNIQUE / PRIMARY KEY / FOREIGN KEY / CHECK / DEFAULT)) impose on that column not fulfilled or not
Example :
For example, we want to create a table “student” with “stu_id” field having a value greater than 100, can create a domain and table like this:
Constraint Creation Template
create domain domain_name int constraint constraint_name check(write codition here);
Constraint Creation Example
create domain age_constraint int constraint age_test check(value > 18);
Table Example
create table student ( student_id PRIMARY KEY, student_name varchar(30), student_age age_constraint int );
Example 2
Constraint Creation Example
create domain roll_no_constraint int constraint roll_test check(value > 0);
Table Example
create table student ( RollNo roll_no_constraint PRIMARY KEY, StudentName varchar(30), StudentPhone int );
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment