Database Systems 1: Lab Session 2
Database Systems 1: Lab Session 2
BAHRAIN POLYTECHNIC
Database Systems 1
Lab Session 2
2
Lab session 2
Data Types
The datatype of a value associates a fixed set of properties with the value.
When a table is created, a datatype for each of its column must be specified.
Datatypes define the domain of values that each column can contain.
Data integrity requires the database to be an accurate reflection of the real world - data must be valid
and complete
Codd (1985) states that integrity constraints specific to a particular RDBMS must be definable in the
RDBMS sublanguage and stored in the system catalogue.
Transactions must be monitored for integrity violations and appropriate actions taken.
Rules should be few, without overlap and should not impact performance significantly.
3
4
Consists of those integrity constraints that are shared by all the attributes that draw their
values from that domain.
Common constraints are regular data types, ranges of values permitted and whether or not
the ordering comparators, > and <, are applicable to these values.
Permits the DBA to define the “business rules” pertaining to the business.
For example, the salary of an employee should not exceed the salary of the employee’s
supervisor.
5
Consider the below example to identify the possible integrity constraints in the below two figures:
Fig 1:
Fig 2:
6
Delete Cascade
The delete of a referenced relation cascades to delete all the matching foreign key tuples
For example, deleting a department from the DEPARTMENT relation would cascade to delete
all matching foreign keys tuples in the EMPLOYEE relation.
When a referenced tuple is deleted, then all the matching foreign key values are set to null
For example, deleting a department from the DEPARTMENT relation would result in all
matching foreign key values in the EMPLOYEE relation being set to null
Can only apply to foreign keys that can accept nulls
When a referenced tuple is deleted, then all the matching foreign key values are set to a
default value
For example, deleting a department from the DEPARTMENT relation would result in all
matching foreign key values in the EMPLOYEE relation being set to a default value
Update rule
Update Restrict
The update operation is restricted if a referenced tuple exists with a foreign key value equal to
a primary key value in the referenced relation. For example, updating the department number
in the DEPARTMENT relation would be restricted if there were matching department numbers
in the EMPLOYEE relation
Default in Oracle
7
Update Cascade
The update of a primary key value cascades to update matching foreign key values in
dependent relations
For example, updating the dept_no in the DEPARTMENT relation would cascade to
update all matching dept_nos in the EMPLOYEE relation.
When a primary key is updated, matching foreign key values in dependent relations are set to
null.
Can only apply to foreign keys that can accept nulls.
For example, updating the dept_no in the DEPARTMENT relation would result in all matching
dept_nos in the EMPLOYEE relation being set to null.
When a primary key is updated, matching foreign key values in dependent relations are set to a
default value
for example, updating the dept_no in the DEPARTMENT relation would result in all matching
dept_nos in the EMPLOYEE relation being set to a default value.
8
I. List the datatypes for each column and specify the reason for the same
II. List the data intergrity constraints for each column and specify the reason s for the same
Multi-Valued Attributes
Consider the below scenario:
A student can enroll in many courses and a course can be taken by more than one student
Student Details
Student_ID Student_Name
201089555 Hayna Lee
201125656 Dee Rai Course Details
201489666 Liam R
201534343 Tim Jew
Course_ID Course_Name
CP1 Computer Programming 1
DB1 Database Systems 1
Enrollment Details
Student_ID Course_Name
201089555 Computer Programming 1
201489666 Computer Programming 1
201089555 Database Systems 1
201534343 Database Systems 1
201489666 Databse Systems 1
1. Can Student_ID be chosen as the primary key in the Enrollment table? If No, specify the reason.
2. How do we resolve this?