SQIT3043 Chapter 2 - Data Models
SQIT3043 Chapter 2 - Data Models
Staff
staffNo fName lName position sex DOB salary branchNo
SL21 John White Manager M 1-Oct-45 30000 B005
SG37 Ann Beech Assistant F 10-Nov-60 12000 B003
SG14 David Ford Supervisor M 24-Mar-58 18000 B003
SA9 Mary Howe Assistant F 19-Feb-70 9000 B007
SG5 Susan Brand Manager F 3-Jun-40 24000 B003
SL41 Julie Lee Assistant F 13-Jun-65 9000 B005
B005 22 Deer Rd London B003 163 Main St Glasgow B007 16 Argyll St Aberdeen
2.4.1 Terminology
a. Relation
A relation(sometimes called file) is a table with column and rows.
An RDMS requires only that the database be perceived by users as tables –
however this only applies to the logical structure of the database and not
the physical structure which can be implemented using variety of storage
structures.
b. Attribute
An attribute (sometimes called field) is a named column of a relation.
In relational model, relations are used to hold information about the objects
to be represented in the database.
A relation is represented as a two-dimensional table in which the rows of the
table correspond to individual records and the table columns correspond to
attributes.
Attributes can appear in any order and the relation will still be the same
relation, and therefore will convey the same meaning.
Figure 2.4 show instances of the Branch and Staff relations. As you can see
in this example, a column contains value of a single attribute; for example,
the branchNo column contain only number of existing branch.
Attributes
Branch
branchNo. street city postCode
B005 22 Deer Rd London SW1 4EH
Cardinality
B007 16 Argyll St Aberdeen AB2 3SU
Relation
Degree
Staff
staffNo fName lName position sex DOB salary branchNo
SL21 John White Manager M 1-Oct-45 30000 B005
SG37 Ann Beech Assistant F 10-Nov-60 12000 B003
Relation
c. Domain
A domain is the set of allowable values for one or more attributes.
Every attribute in a relation is defined on a domain.
Domain may be distinct for each attribute, or two or more attributes may be
defined on the same domain.
Figure 2.5 shows the domain for some of the attributes of the Branch and
Staff relations.
The domain concept is important, because it allows the user to define in a
central place the meaning and source of values that attributes can hold. As
a result, more information is available to the system when it undertakes the
execution of a relational operation, and operations that are semantically
incorrect can be avoided. Eg; it is not sensible to compare an street name
with a telephone number, even though the domain definitions for both of
these attributes are character strings.
Attribute Domain Name Meaning Domain Definition
branchNo BranchNumber The set of all possible branch numbers Character: size 4, range B001 – B999
street StreetNames The set of all street names in Britain Character: size 25
city CityNames The set of all city names in Britain Character: size 15
postcode Postcodes The set of all postcodes in Britain . Character: size 8
sex Sex The sex of a person Character : size 1, value M or F
DOB DateOfBirth Possible values of staff birth date Date, range from 1-Jan-20, format
dd-mm-yy
salary Salaries Possible values of staff salaries Monetary : 7 digits, range 6000.00 –
40000.00
Figure 2.5 Domains for some attributes of the Ward and Staff relations.
d. Tuple
A tuple is a row of a relation (sometimes called record).
Tuples can appear in any order and the relation will still be the same relation,
and therefore convey the same meaning.
The structure of a relation, together with a specification of the domains and
any other restrictions on possible values, is sometimes called its intention,
which is usually fixed, unless the meaning of a relation is changed to include
additional attributes.
The tuples are called the extension (or state) of a relation, which changes
over time.
e. Degree
The degree of a relation is the number of attributes it contains.
The Ward relation in figure 2.4 has five attributes or degree five.
A relation with only one attribute would have degree one and be called a
unary relation or one tuple.
A relation with two attributes is called binary, one with three attributes is
called ternary, and after that the term n-ary is usually used.
The degree of a relation is the property of the intention of the relation.
f. Cardinality
The cardinality of a relation is the number of tuples it contains.
This changes as tuples are added or deleted.
The cardinality is a property of the extension and is determined from the
particular instance of the relation at any given moment.
g. Relational Database
A relational database is a collection of normalized relations with distinct
relation names.
Normalization is a process of structuring relations into an appropriate form.
This will be covered in chapter 5.
D1 x D2 x D3 = {(1,2,5),(1,2,6),(1,4,5),(1,4,6),(3,2,5),(3,2,6),(3,4,5),(3,4,6)}
Any subset of these ordered triples is a relation.
We can extend the three sets and define a general relation on n domains.
Let D1, D2,……., Dn be n sets. Their Cartesian product is defined as;
D1 x D2 x…. xDn = {(d1,d2,…..,dn)| d1 D1 , d2 D2,……, dn Dn }
and is usually written as,
n
D
i 1
1
Any set of n-tuples from this Cartesian product is a relation of the N sets.
Note that in defining these relations we have to specify the sets, or domains
from which we choose values.
c. Primary key
The candidate key that is selected to identify tuples uniquely within the
relation.
Because a relation has no duplicate tuples, it is always possible to identify
each row uniquely. This means that a relation always has a primary key.
In the worst case, the entire set of attributes could serve as the primary key.
The candidate keys that are not selected to be the primary keys are called
alternate keys.
For branch relation, if we choose branchNo as the primary key, postcode
would then be an alternate key.
Branch
branchNo street city postcode
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
B002 56 Clover Dr London NW10 6EU
Staff
staffNo fName lName position sex DOB salary branchNo
SL21 John White Manager M 1-Oct-45 30000 B005
SG37 Ann Beech Assistant F 10-Nov-60 12000 B003
SG14 David Ford Supervisor M 24-Mar-58 18000 B003
SA9 Mary Howe Assistant F 19-Feb-70 9000 B007
SG5 Susan Brand Manager F 3-Jun-40 24000 B003
SL41 Julie Lee Assistant F 13-Jun-65 9000 B005
PropertyForRent
propertyNo street city postcode type rooms rent ownerNo staffNo branchNo
PA14 16 Hollhead Aberdeen AB7 5SU House 6 650 C046 SA9 B007
PL94 6 Argyll St London NW2 Flat 4 400 C087 SL41 B005
PG4 6 Lawrence St Glasgow G11 9QX Flat 3 350 C040 B003
PG36 2 Manor Rd Glasgow G32 4QX Flat 3 375 C093 SG37 B003
PG21 18 Dale Rd Glasgow G12 House 5 600 C087 SG37 B003
PG16 5 Novar Dr Glasgow G12 9AX Flat 4 450 C093 SG14 B003
Client
clientNo fName lName telNo prefType maxRent eMail
CR76 John Kay 0207-774-5632 Flat 425 [email protected]
CR56 Aline Stewart 0141-848-1825 Flat 350 [email protected]
CR74 Mike Ritchie 01475-392178 House 750 [email protected]
CR62 Mary Tregear 01224-196720 Flat 600 [email protected]
PrivateOwner
ownerNo fName lName address telNo eMail password
C046 Joe Keogh 2 Fergus Dr, Aberdeen AB2 7SX 01224-861212 [email protected] ******
C087 Carol Farrel 6 Achray St, Glasgow G32 9DX 0141-357-7419 [email protected] ******
C040 Tina Murphy 63 Well St, Glasgow G42 0141-943-1728 [email protected] ******
C093 Tony Shaw 12 Park Pl, Glasgow G4 0QR 0141-225-7025 [email protected] ******
Viewing
clientNo propertyNo ViewDate comment
CR56 PA14 24-May-08 Too small
CR76 PG4 20-Apr-08 Too remote
CR56 PG4 26-May-08
CR62 PA14 14-May-08 No dining room
CR56 PG36 28-May-08
Registration
clientNo branchNo staffNo dateJoined
CR76 B005 SL41 2-Jan-08
CR56 B003 SG37 11-Apr-07
CR74 B003 SG37 16-Nov-06
CR62 B007 SA9 7-Mar-07
a. Nulls
Represents a value for an attribute that is currently unknown or is not applicable
for this tuple.
A null can be taken to mean the logical value ‘unknown’. It can mean that a
value is not applicable to a particular tuple, or it could merely mean that no
value has yet been supplied.
Nulls are a way to deal with incomplete or exceptional data.
However null is not the same as a zero numeric value or a text string filled with
spaces; zeros and spaces are values, but a null represents the absence of a
value.
For example, in the Viewing relation shown in figure 2.6, the comment attribute
may be undefined until the potential renter has visited the property and
returned his or her comment to the agency. Without nulls, it becomes necessary
to introduce false data to represents this state or to add additional attributes
that may not be meaningful to user. In our example, we may try to represent a
null comment with value -1. Alternatively, we may add a new attribute
hasCommentBeenSupplied to the viewing relation, which contains a Y (Yes) and
N (No). Both these approach can be confusing to the user.
b. Entity Integrity
This rule applies to the primary keys of base relations.
For the present we define a base relation as a relation that corresponds to an
entity in the conceptual schema.
Entity integrity – means, in a base relation, no attribute of a primary key can be
null.
If we allow a null for any part of a primary key, we are implying that not all the
attributes are needed to distinguish between tuples, which contradicts the
definition of the primary key.
Hence in our example, we should not be able to insert a tuple into the Branch
relation with a null for the branchNo attribute.
c. Referential Integrity
This rule applies to foreign key.
Referential integrity – means, if a foreign key exists in a relation, either the foreign
key value must match a candidate key value of some tuple in its home relation
or the foreign key value must be wholly null.
For example, branchNo in the Staff relation is a foreign key targeting the
BranchNo attribute in the home relation, Branch. It should not be possible to
create a staff record with branch number B025, for example, unless there is
already a record for branch number B025 in Branch relation.
d. General Constraints
General constraints are additional rules specified by the users or database
administrators of a database that define or constrain some aspect of the
enterprise.
It is also possible for users to specify additional constraints that the data must
satisfy. For example, if an upper limit of 20 has been placed upon the number of
staff that may work at a branch office, then the user must be able to specify this
general constraint and expect the DBMS to enforce it. In this case it should not
be possible to add a new staff member at a given branch to the Staff relation if
the number of staff currently assigned to that branch is 20.
SOURCE:
Codd, E. F. (1970). A Relational Model for Large Shared Data Banks. Communications of the
ACM, 13(6), 377-387.
REFERENCES:
Connoly, T., & Begg, C. (2010). Database Systems Apractical Approach to Design, Implementation,
and Management (5 ed.). Boston: Pearson.
Elmasri, R., & Navathe, S. B. (2011). Database Systems Models, Languages, Design and Application
Programming (6 ed.). Boston: Pearson.
Garcia-Mollina, H., Ullman, J. D., & Wildom, J. (2009). Database Systems The Complete Book.
New Jersey: Prentice Hall.
Hull, R., & King, R. (1987). Semantic Database Modelling - Surveys, Applications and Research
Issues. ACM Computing Survey, 19(3), 201-260.
Peckham, J., & Maryanski, F. (1988). Semantic data models. ACM Comput. Surv., 20(3), 153-189.