0% found this document useful (0 votes)
8 views23 pages

Integrity - Constraints and FD

Uploaded by

kadsjzzzz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views23 pages

Integrity - Constraints and FD

Uploaded by

kadsjzzzz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Integrity Constraints

In SQL
Integrity Constraints

• 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.
Types of Integrity Constraints
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.
2. Entity integrity constraints
• 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.
3. Referential
Integrity Constraints

• A referential integrity constraint


is specified between two tables.
• In the Referential integrity
constraints, if a foreign key in
Table 1 refers to the Primary Key
of Table 2, then every value of
the Foreign Key in Table 1 must
be null or be available in Table 2.
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.
Functional Dependency

• The functional dependency is a relationship that exists between two


attributes. It typically exists between the primary key and non-key
attribute within a table.
X → Y
• The left side of FD is known as a determinant, the right side of the
production is known as a dependent.
FD
For example:
• Assume we have an employee table with attributes: Emp_Id,
Emp_Name, Emp_Address.
• Here Emp_Id attribute can uniquely identify the Emp_Name attribute
of employee table because if we know the Emp_Id, we can tell that
employee name associated with it.
• Functional dependency can be written as:
Emp_Id → Emp_Name
• We can say that Emp_Name is functionally dependent on Emp_Id.
Types of
Functional
dependency
1. Trivial functional dependency

• A → B has trivial functional dependency if B is a subset of A.


• The following dependencies are also trivial like:
A → A, B → B
Consider a table with two columns Employee_Id and Employee_Name.
{Employee_id, Employee_Name} → Employee_Id
is a trivial functional dependency as
Employee_Id is a subset of {Employee_Id, Employee_Name}.
Also, Employee_Id → Employee_Id and Employee_Name → Emplo
yee_Name are trivial dependencies too.
2. Non-trivial functional dependency

• A → B has a non-trivial functional dependency if B is not a subset of


A.
• When A intersection B is NULL, then A → B is called as complete
non-trivial.
Example:
1.ID → Name,
2.Name → DOB

You might also like