Relational Model Constraints Domain constraints

For Complete YouTube Video: Click Here

In this class, we will understand Relational Model Constraints Domain constraints.

We have already discussed the concepts of the domain.

Relational Model Constraints Domain constraints

We will discuss the concept of domain more deeply.

Before understanding the domain, we will discuss constraints.

Constraints

Constraints are the restrictions on the actual values in a database.

When we have to insert into the database, we should impose some constraints on those values.

Those constraints are for better management of data in the database.

There are different types of constraints.

  1. Domain Constraint 
  2. Key Constraint
  3. NULL value constraint
  4. Referential Integrity Constraint

Domain Constraint

In this class, we will discuss ‘domain constraint.’

Domain Constraint specifies that within each tuple, the value of each attribute must be an atomic value from the domain.

Whenever we have a tuple inserted into the database, the tuple should be a simple value from that specific domain.

How can we decide the domain?

The domain of values inserted is decided from the data type specified while creating the table.

For example, if we consider the employee table, where the SSN column is specified as SSN int(10), the values inserted into the SSN should not be more than ten digits ant the ‘value’ should be an integer.

Violation of domain constraint

We will try to violate the domain constraint and see what happens.

The command below is the violation of SSN size by inserting more than ten digits.

INSERT INTO employee (Fname, Minit, Lname, SSN, Bdate, Address, Sex, Salary, Dno) VALUES (‘James’, ‘E’, ‘Borg’, 88866555555555, ’10-NOV-1937′, ‘430 Stone, Houston, TX’, ‘M’, 55000, 1);

The error message is as shown below.

Relational Model Constraints Domain constraints
Relational Model Constraints Domain constraints

Similarly, let us try another way, as shown below.

INSERT INTO employee (Fname, Minit, Lname, SSN, Bdate, Address, Sex, Salary, Dno) VALUES (‘James’, ‘E’, ‘Borg’, 88866fga, ’10-NOV-1937′, ‘430 Stone, Houston, TX’, ‘M’, 55000, 1);

Here we are trying to insert characters into a column that is specified as an integer.

The error message is as shown below.

Relational Model Constraints Domain constraints 2
Relational Model Constraints Domain constraints 2