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

Lesson03-Relational Integrity Constraints

Uploaded by

mwangibrian1293
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Lesson03-Relational Integrity Constraints

Uploaded by

mwangibrian1293
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

3 Lesson 3: Relational Integrity Constraints

Relational integrity constraints in DBMS are referred to conditions which must be present for a valid
relation. Constraints on the Relational DBMS are divided into three main categories:

 Domain Constraints
 Key Constraints
 Referential Integrity Constraints

Domain Constraints

Domain constraints can be violated if an attribute value is not appearing in the corresponding domain
or it is not of the appropriate data type. Each table has certain set of columns. Each column only allows
entry of same type of data, based on the data type specified during table definition. The column does
not accept values of any other data type.

Thus domain constraints can be defines as follows;

Domain Constraint = data type +Other Constraints (NOT NULL / UNIQUE / CHECK /
DEFAULT)
Key Constraints

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.

Example: In the given table, StudentID is a key attribute of students table. It is most likely
to have a single key for one student, StudentID =1 is only for the student name " Alex
Jones".

StudentID StudentName phone email


1 Alex Jones 0721 001001 [email protected]
2 Maria Joseph 0721 052073 [email protected]
3 Cathy Peters 0721 501789 [email protected]
Referential Integrity Constraints
Referential Integrity constraints in DBMS are based on the concept of Foreign Keys. A foreign
key is an important attribute of a relation which should be referred to in other relationships.
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.

Example: In the example below, we have 2 relations, students and programs. The tuple
for ProgramID =11 in the programs relation is referenced twice in the relation students.

SID StudentName phone email FK_pid


1 Alex Jones 0721 001001 [email protected] 11
2 Maria Joseph 0721 052073 [email protected] 11
3 Cathy Peters 0721 501789 [email protected] 13

1
PID Program DepartmentID
11 BSc. Computer Science 1
12 BSc. Statistics 2
13 BSc. Data Science 3
Operations in Relational Model

The basic update operations performed on relational database model are: Insert, update, delete
and select.

 Insert is used to insert data into the relation


 Update allows you to change the values of some attributes in existing tuples.
 Delete is used to delete tuples from the table.
 Select allows you to choose a specific range of data.

Whenever one of these operations is performed, integrity constraints specified on the


relational database schema must never be violated, else the operation is aborted.
Insert Operation

The insert operation gives values of the attribute for a new tuple which should be inserted into
a relation.

ProgramID Program DepartmentID


11 BSc. Computer Science 1
12 BSc. Statistics 2
13 BSc. Data Science 3
14 BSc. Economics 7
Update Operation

Example: In programs table, the tuple with program as 'BSc. Data Science’ is edited
with the attribute DepartmentID being updated from 3 to 1.

ProgramID Program DepartmentID


11 BSc. Computer Science 1
12 BSc. Statistics 2
13 BSc. Data Science 1
14 BSc. Economics 7
Delete Operation

To specify deletion, a condition on the attributes of the relation selects the tuple to be deleted.

Example: From the programs relation, delete the tuple(s) with program name as “BSc. Data
Science”.

2
ProgramID Program DepartmentID
11 BSc. Computer Science 1
12 BSc. Statistics 2
14 BSc. Economics 7
The Delete operation could violate referential integrity if the tuple which is deleted is
referenced by foreign keys from other tuples in the same database.
Select Operation

Example: From the programs relation, select the tuples satisfying the condition Program=
‘BSc. Statistics’

ProgramID Program DepartmentID


12 BSc. Statistics 2

Lab: ER Modelling Case Study

Consider the following data requirements that were provided by a college to aid in the development of
their ERP system.

XYZ college is a higher learning institution that offers training in various disciplines such as
Pharmacy, Engineering, Music, among others. The college is structured into various departments
where each department runs one or more programs. For Example, the programs Diploma in
Pharmacy, and Certificate in Pharmacy are housed in the Department of Pharmacy. Each program
is composed of a finite number of course units. Course units are identified using unit codes, unit
titles, credit hours, and unit type. Some units are shared across several programs in the college.
For instance, course units of the type “common units” are shared by all programs in the college;
“departmental units” are shared by all programs in a department, while “core units” are not shared
at all.

Students in the college are identified using admission number, names, email, phone, etc. A student
can be enrolled to only one program. The college maintains a register of Trainers using their
employment number, names, email, phone, ID number etc. In addition, each trainer belongs to one
of the various departments of the college.

The college adopts learning terms, which runs concurrently for all programs. Each term has a
name, start date, end date, exam date as its attributes e.g. the term “JAN_MAR_2020” begins on
01/01/2020, and ends on 31/03/2020, and exams begin on 23/03/2020.

At the onset of each term, a sub set course units are offered by each department. Students can only
register for one or more course units that have been put on offer. A trainer is assigned to teach one
or more course units that are on offer. Thus, a separate entity “courses on offer” is maintained
with the following attributes: course unit, term, trainer, venue, date, and time.

Required:

i. Identify and list all entities that can be derived from these requirements.
ii. Identify and list the relationships between the entities in (i) above, where applicable.

3
iii. Identify the cardinality of the relationships between the entities in (i) above, where
applicable.
iv. Identify and list the attributes of each of the entities in (i) above.
v. Create a suitable E-R model based on information identified in (i) to (iv) above.

You might also like