Ch6 - Constraints in Relational Model
Ch6 - Constraints in Relational Model
There are many types of integrity constraints. Constraints on the Relational database
management system is mostly divided into three main categories are:
1. Domain constraints
2. Entity integrity or Key/primary key constraints
3. Referential integrity constraints
Relational Integrity constraints or RULES
NOT NULL Constraint
By default, a column can hold NULL values.
If CUSTOMERS table has already been created, then to add a NOT NULL constraint
to the SALARY column in
For example, the following SQL query creates a new table called CUSTOMERS and adds
five columns.
Here, the AGE column is set to UNIQUE, so that you cannot have two records with the
same age.
An attribute that can uniquely identify a tuple in a relation is called the key of the
table.
The value of the attribute for different tuples in the relation has to be unique.
• If the primary key is a composite key, none of the fields in the key can contain a
null value.
Entity Integrity OR Key/Primary Key constraints
Example:
• In the given table, CustomerID is a key attribute of Customer Table.
• It is most likely to have a single key for one customer, CustomerID =1 is only for the
CustomerName =" Google".
Referential integrity constraint state happens where relation refers to a key attribute
of a different or same relation. However, that key element must exist in the table.
Referential Integrity
Referential Integrity can help avoid data input errors, voids data inconsistency and
to
quality
problems.
In a relational database, referential integrity means that a foreign key value cannot
be entered in one table unless it matches an existing primary key in another
table.
You cannot change a primary key that has matching child table records