0% found this document useful (0 votes)
65 views

7 Relational Integrity Constraints

The document discusses various types of relational integrity constraints: 1) Domain constraints specify the range of values for table columns. 2) Tuple uniqueness constraints require all tuples to be unique. 3) Key constraints include primary keys to uniquely identify records and foreign keys to reference other tables' primary keys. 4) Entity integrity constraints like NOT NULL prevent primary keys from being null. 5) Referential integrity constraints require foreign keys to reference existing primary keys or be null.

Uploaded by

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

7 Relational Integrity Constraints

The document discusses various types of relational integrity constraints: 1) Domain constraints specify the range of values for table columns. 2) Tuple uniqueness constraints require all tuples to be unique. 3) Key constraints include primary keys to uniquely identify records and foreign keys to reference other tables' primary keys. 4) Entity integrity constraints like NOT NULL prevent primary keys from being null. 5) Referential integrity constraints require foreign keys to reference existing primary keys or be null.

Uploaded by

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

Relational Integrity constraints

Relational Integrity constraints is referred to

 conditions which must be present for a valid relation.

There are many types of Relational integrity constraints.

1. Domain Constraints (CHEQUE Constraint)

 This constraint is used for specifying range of values for a particular


column (attribute) of a table.

 Domain constraint defines the domain or set of values for an attribute.

 It specifies that the value taken by the attribute must be the atomic value from its
domain.

 The attribute must follow the data types which include standard data types
integers, real numbers, characters, Booleans, variable length strings, etc.

Example:

Consider the following Student table-

STU_ID Name Age

S001 Akshay 20
S002 Abhishek 21

S003 Shashank 20

S004 Rahul A

Here, value ‘A’ is not allowed since only integer values can be taken by the age attribute.
Example-SQL statement with check Constraint

CREATE TABLE STUDENT(

ROLL_NO INT CHECK(ROLL_NO >1000),


STU_NAME VARCHAR (35),
STU_AGE INT ,
STU_ADDRESS VARCHAR (35)
);

2. Tuple Uniqueness Constraint (UNIQUE Constraint)-

 Tuple Uniqueness constraint specifies that all the tuples must be necessarily
unique in any relation.

Example-01:
Consider the following Student table-

STU_ID Name Age

S001 Akshay 20

S002 Abhishek 21

S003 Shashank 20

S004 Rahul 20

This relation satisfies the tuple uniqueness constraint since here all the tuples are
unique.
Example-02:
Consider the following Student table-

STU_ID Name Age

S001 Akshay 20
S001 Akshay 20

S003 Shashank 20

S004 Rahul 20

This relation does not satisfy the tuple uniqueness constraint since here all the tuples are
not unique.

3. Key constraints (PRIMARY KEY and FOREIGN KEY constraints):

Primary key uniquely identifies each record in a table. It must have unique values
and cannot contain nulls.

Foreign keys are the columns of a table that points to the primary key of another
table. They act as a cross-reference between tables.

 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:

4. Entity integrity constraints (NOT NULL)

• 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:
5. Referential Integrity Constraints

 A referential integrity constraint is specified between two tables.

 It specifies that all the values taken by the foreign key must either be available in
the relation of the primary key or be null.

 Foreign keys are the columns of a table that points to the primary key of
another table. They act as a cross-reference between 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.

Example1:
Example2:

Consider the following two relations- ‘Student’ and ‘Department’.


Here, relation ‘Student’ references the relation ‘Department’.

Student Department

STU_I Dept_no Dept_name


Name Dept_no
D
D10 ASET
S001 Akshay D10
D11 ALS
S002 Abhishek D10
D12 ASFL
S003 Shashank D11 •
D13 ASHS
S004 Rahul D14 • The relation
‘Student’ does not satisfy the referential
integrity constraint.
• This is because in relation ‘Department’, no value of primary key specifies
department no. 14.
• Thus, referential integrity constraint is violated.

You might also like