Notes Chapter 1.1 Lecture 1.5(Integrity)
Notes Chapter 1.1 Lecture 1.5(Integrity)
CHAPTER 1.1
Lecture-1.5 (Integrity)
Integrity Constraints
Integrity constraints in Database Management Systems (DBMS) are a set of rules that are
applied on the table columns or relationships to ensure that the overall validity, integrity, and
consistency (i.e. the quality) of the data present in the database table is maintained. Each and
every time a table insert, update, delete, or alter operation is performed, it is evaluated against
the terms or rules mentioned in the integrity constraint. The data is inserted, updated, deleted,
or altered only if the result of the constraint comes out to be True. Thus, integrity constraint
prevents accidental damage to the database by an authorized user.
Integrity constraints are a set of rules. It is used to maintain the quality of information.
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.
These are the constraints on the domain value and thus are column level constraints unlike
entity integrity constraint which are row level. The domain integrity constraints are used to
impose restrictions on some particular column. Thus they affect the domain value. These can
be enforced in the form of the following-
Check value
Default value
Check is used to impose certain checks like checking if a value is greater than or lesser than a
particular value etc. thus the upper and the lower limit can be set.
Default value is the value to be provided in case no value is provided by the user. We can set
a default value for any column depending on its data-type. These are also used during
defining the structure of the tables, in the data definition language statements.
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:
Entity integrity constraints as the name implies is applied on each entity. i.e. it is applied on
individual rows. The constraint here is to have a unique value for each row in the column or a
group of columns it is applied to. This attribute is essential when a particular record or row of
data is to be accessed. It can be accessed using the entity integrity constraint by supplying the
unique value and accessing the entire record.
There are two such constraints which ensure uniqueness of data. They are-
Primary key
Unique keyword
Primary key ensures that values in a column are unique so that duplicate values are not
allowed and also the primary key column cannot be null. Thus it focuses on two properties-
uniqueness and not null. A table can contain only one primary key. Primary key can consist
of a column or a group of columns. It is used to uniquely identify records in a table.
Unique keyword is just like the primary key but it allows null values. Both these are defined
on columns during defining the structure of table. Thus these are used in data definition
language.
The entity integrity constraint states that primary key value can't be null.
This is because the primary key value is used to identify individual rows in relation
and if the primary key has a null value, then we can't identify those rows.
A table can contain a null value other than the primary key field.
Example:
Referential integrity constraint makes sure that the values in the column on which it is
applied are already present in the column it is referring to. Thus here a column of a table
refers to the other column of the same or different table. This ensures that the values are
consistent and similar in both the columns. This is implemented using-
Foreign key
Foreign key normally references the primary key of same or another table. But it can refer to
other columns too. Whenever, same type of attribute exists in two different tables, the
attribute in one of the table is declared as the primary key and in the other, it is made foreign
key, so that the values in both become consistent. Foreign key is dependent on primary key.
Example:
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.
Example:
OTHER REFRENCES