Constraints 1
Constraints 1
Constraints are the set of rules used to maintain the quality of information. In this context,
integrity constraints ensure that the data insertion, updating, and other processes have to be
performed in such a way that data integrity is not affected. Thus, integrity constraint is used to
guard against accidental damage to the database.
CONSTRAINT TYPES
1. Domain constraints
Domain constraints can be defined as the definition of a valid set of values for an
attribute.
The data type of domain includes string, character, integer, time, date, currency, etc. The
value of the attribute must be available in the corresponding domain. Example:
Example 1:
CREATE TABLE Orders (
OrderID int NOT NULL,
OrderNumber int NOT NULL,
PersonID int,
PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)
);
4. Key constraints
Keys are the entity set that is used to identify an entity within its entity set uniquely.
An entity set can have multiple keys, but out of which one key will be the primary key. A
primary key can contain a unique and null value in the relational table.