2. Objectives
• In this lecture, you will learn:
– Some relational model terminologies
– The difference between the relation schema and
relational database schema
– The properties of a relation
– Relational keys
– Relational intergrity
– Views and purpose of views in relational database
2
3. Relational Model Terminology
• An entity is a person, place, event, or
thing/Object for which we intend to collect
data
• Examples:
– University -- Students, Faculty Members, Courses
– Airline -- Pilots, Aircraft, Routes, Suppliers
• A relation is a table with columns and rows.
– Only applies to logical structure of the database,
not the physical structure.
4. Relational Model Terminology
• Attribute is a named column of a relation.
• Example:
– Student -- Student Number, Name...etc
• Domain is the set of allowable values for one
or more attributes.
Attribute Domain Name Meaning Domain
Definition
Stu_id StudentID ID of a student Character:
Size 10
5. Relational Model Terminology
• Tuple is a row of a relation.
• Degree is the number of attributes in a relation.
• Cardinality is the number of tuples in a relation.
• Relational Database
– A collection of normalized relations with distinct
relation names.
11. Database Relations
• Relation schema
• Named relation defined by a set of attribute and domain
name pairs.
• Relational database schema
• Set of relation schemas, each with a distinct name.
12. Relation and Relational Schema
• A relation schema is the name and the list of
attributes of a relation
• Example:
– Grade (studentId, assignmentId, points, dateSubmitted)
Relational Schema
13. Properties of Relation
• Relation name is distinct from all other relation names
in relational schema.
• Each cell of relation contains exactly one atomic (single)
value.
• Each attribute has a distinct name.
• Values of an attribute are all from the same domain.
• Each tuple is distinct; there are no duplicate tuples.
• Order of attributes has no significance.
• Order of tuples has no significance, theoretically.
14. Relational Keys
• Super key
– An attribute, or a set of attributes, that uniquely identifies a
tuple within a relation.
• Candidate Key
– Super key (K) such that no proper subset is a super key within
the relation.
• Candidate key, K, for a relation R has two properties
– Uniqueness - in each tuple of R, values of K uniquely identify
that tuple.
– Irreducibility - no proper subset of K has the uniqueness
property
15. Relational Key
• Super key
– Uniquely identifies each entity
• STU_NUM
• STU_NUM, STU_LNAME
• STU_NUM, STU_LNAME, STU_INIT
• Candidate key
– Minimal super key
• STU_NUM
• STU_LNAME, STU_FNAME, STU_INIT, STU_PHONE
• When a key consists of more than one attribute, it is
called a composite key
16. Example
• Which attributes of this table can be used as a candidate
key?
• BranchNo and PostalCode can be used as candidate keys.
• City attribute cannot be used as a candidate key, because it
has duplicate values.
BranchNo Street City PostalCode
B005 22 Deer Rd London SW1 4EH
B007 16 Argyll St Aberdeen AB2 3SU
B003 163 Main St Glasgow G11 9QX
B004 32 Manse Rd Bristol BS99 1NZ
B003 56 Clover Dr London NW10 6EU
17. Relational Key
• Primary Key
– Candidate key selected to identify tuples uniquely within
relation.
• Alternate Keys
– Candidate keys that are not selected to be primary key.
• Foreign Key
– Attribute, or set of attributes, within one relation that matches
candidate key of some (possibly same) relation
18. Relational Integrity
• Null
– Represents value for an attribute that is currently unknown or
not applicable for tuple.
– Deals with incomplete or exceptional data.
– Represents the absence of a value and is not the same as zero
or spaces, which are values.
– Example: if a student is absent for the final exam. The final
exam value of that student should be null.
19. Relational Integrity
• Entity Integrity
– In a base relation, no attribute of a primary key can be null.
• Primary key (BranchNo)
• Cannot insert a tuple in this relation if BranchNo is null.
BranchNo Street City PostalCode
B005 22 Deer Rd London SW1 4EH
B007 16 Argyll St Aberdeen AB2 3SU
B003 163 Main St Glasgow G11 9QX
B004 32 Manse Rd Bristol BS99 1NZ
B006 56 Clover Dr London NW10 6EU
20. Relational Integrity
• Entity Integrity
– In a base relation, no attribute of a primary key can
be null.
• Composite primary key (ClientNo, PropertyNo)
• Cannot insert a tuple in this relation if either ClientNo
is null, PropertyNo is null or both ClientNo and
PropertyNo are null.
ClientNo PropertyNo ViewDate Comment
CR56 PA14 24 May 01 Too small
CR76 PG4 20 April 01 Too remote
CR56 PG4 16 May 01
CR62 PA14 14 May 01 No dining room
CR56 PG36 28 April 01
21. Relational Integrity
• Referential Integrity
– If foreign key exists in a relation, either foreign key value
must match a candidate key value of some tuple in its home
relation or foreign key value must be wholly null.
22. 22
Relational Integrity
BranchNo Street City PostalCode
B005 22 Deer Rd London SW1 4EH
B007 16 Argyll St Aberdeen AB2 3SU
B003 163 Main St Glasgow G11 9QX
B004 32 Manse Rd Bristol BS99 1NZ
B006 56 Clover Dr London NW10 6EU
staffNo fName lName Position Sex Salary BranchNo
SL21 Jhon White Manager M 30000 B005
SG37 Ann Beech Assistant F 12000 B003
SG14 David Ford Supervisor M 18000 B003
SA9 Mary Howe Assistant F 9000 B007
SG5 Susan Brand Manager F 24000 B003
SL41 Julie Lee Assistant F 9000 B005
23. Referential Integrity: Example
• BranchNo in the staff relation is a foreign key
targeting the BranchNo attribute in the Branch
relation.
• Not possible to create a staff record with non
existing BrancNo (example with B025)
• But it is possible to create a staff record with a
null branch number to cater for new staff who
has not assigned any branch office.
23
24. Referential Integrity: Example
• Consider the situation where we have two tables:
Employees and Managers. The Employees table
has a foreign key attribute entitled ManagedBy
which points to the record for that employee’s
manager in the Managers table.
– We may not add a record to the Employees table
unless the ManagedBy attribute points to a valid
record in the Managers table.
– If the primary key for a record in the Managers table
changes, all corresponding records in the Employees
table must be modified using a cascading update.
– If a record in the Managers table is deleted, all
corresponding records in the Employees table must be
deleted using a cascading delete.
24
25. Views
• Base Relation
– Named relation corresponding to an entity in conceptual schema,
whose tuples are physically stored in database.
• View
– Dynamic result of one or more relational operations operating on
base relations to produce another relation.
– A view is a virtual relation that does not necessarily exists in a
database but can be produced upon request.
– Contents of a view are defined as a query on one or more base
relations.
– Views are dynamic, meaning that changes made to base relations
that affect view attributes are immediately reflected in the view.
27. Purpose of Views
• Provides powerful and flexible security mechanism by hiding
parts of database from certain users.
• Permits users to access data in a customized way, so that same
data can be seen by different users in different ways, at the
same time.
• Can simplify complex operations on base relations ( Example:
join).
• A view should be designed to support external model:
– Some members of the staff should be able to see staff tuples
without the salary attribute.
– Attributes may be renamed or the order of attributes changed.
– Some members of the staff should see only a specific records.
Editor's Notes
LOGICAL STRUCTURE OF DATABASE
Logical structure mainly consists of tablespace, segments, extents, and oracle data blocks
TABLESPACE
Each database is logically divided into one or more tablespaces. One or more datafiles are explicitly created for each tablespace to physically store the data of all logical structures in a tablespace. The combined size of the datafiles in a tablespace is the total storage capacity of the tablespace.
SEGMENT
A segment is a set of extents allocated for a certain logical structure. The segments can be of one of following type data segment,index segment,temporary segment,rollback segment.
EXTENT
The next level of logical database space is an extent. An extent is a specific number of contiguous data blocks, obtained in a single allocation, used to store a specific type of information.
ORACLE DATABLOCKS
At the finest level of granularity, Oracle database data is stored in data blocks. One data block corresponds to a specific number of bytes of physical database space on disk. The standard block size is specified by the DB_BLOCK_SIZE initialization parameter. In addition, you can specify up to five other block sizes.
Definition: Referential integrity is a database concept that ensures that relationships between tables remain consistent. When one table has a foreign key to another table, the concept of referential integrity states that you may not add a record to the table that contains the foreign key unless there is a corresponding record in the linked table. It also includes the techniques known as cascading update and cascading delete, which ensure that changes made to the linked table are reflected in the primary table. Consider the situation where we have two tables: Employees and Managers. The Employees table has a foreign key attribute entitled ManagedBy which points to the record for that employee’s manager in the Managers table. Referential integrity enforces the following three rules: We may not add a record to the Employees table unless the ManagedBy attribute poi
nts to a valid record in the Managers table. If the primary key for a record in the Managers table changes, all corresponding records in the Employees table must be modified using a cascading update.
If a record in the Managers table is deleted, all corresponding records in the Employees table must be deleted using a cascading delete.