Lesson03-Relational Integrity Constraints
Lesson03-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.
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".
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.
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.
The insert operation gives values of the attribute for a new tuple which should be inserted into
a relation.
Example: In programs table, the tuple with program as 'BSc. Data Science’ is edited
with the attribute DepartmentID being updated from 3 to 1.
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’
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.