THE RELATIONAL DATABASE MODEL
What is a data model
A model is a representation of of real world objects and events and their associations. A data
model is an intergrated collection of concepts for describing data, relationship between
data,and any constarint on the data. A data model should provide the basic concepts and
notations that will allow database designers and end users to communicate their understanding
of the organization data unambiguously and accurately.
A data model comprises of three components:
i. Structural part- consists of a set of rules that define how the database is to be
constructed.
ii. Manipulative part- defines the types of operations (transactions ) that are allowed on
the data.
iii. A set of integrity rules that ensures that data is accurate.
There are different types of data models
i. Hierachical model
ii. Network model
iii. The relational model
iv. The object oriented model
v. The object relational model
The relational model
The relational model is based on the mathematical concept of a relation, which is physically
represented as a table. Codd, a trained mathematician, used terminology taken from
mathematics, principally set theory and predicate logic. A relation is a table with rows and
colums. A relational DBMS requires that the database be perceived by the user as tables.
Note that this perception applies only to the way we view the database; it does not apply to
the physical structure of the database on disk, which is implemented using a variety of storage
structures (such as a heap file or hash file).
In the relational model, we use relations to hold information about the objects that we want to
represent in the database. We represent a relation as a 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.
Relational databases which are based on the relational model remain by far the most popular
database systems used in organizations today. The relational model has become widely
accepted because of its conceptual simplicity and its sound theretical basis.
Relational concepts
Domain
The set of allowable values for one or more attributes. Domains are an important feature of
the relational model because they help us to define the meaning and source of values that
attributes can hold. As a result more information is available to the system and it can reject
operations that dont make sense.
Tuple
The fundamental elements of a relation are tuples or records in a table. Its a row of a relation
and it represents an instance of a relation
Relation
A table or flat file with with columns and rows which have certain properties
Attribute
A named column of a table
Degree
The degree of a relation is the number of attributes it contains
Cardinality
The cardinality of a relation is the number of tuples it contains
The Relational Database
A relational database is a collection of tables that are appropriately structured. The
appropriateness is achieved through the process normalisation.
Properties of relational tables
A relational table has the following properties:
The table has a name that is distinct from all other tables in the database.
Each cell of the table contains exactly one value. (For example, it would be wrong to
store several telephone numbers for a single branch in a single cell. In other words,
tables don't contain repeating groups of data. A relational table that satisfies this
property is said to be normalized or in first normal form.)
Each column has a distinct name.
The values of a column are all from the same domain.
The order of columns has no significance. In other words, provided a column name is
moved along with the column values, we can interchange columns.
Each record is distinct; there are no duplicate records.
The order of records has no significance, theoretically. (However, in practice, the
order may affect the efficiency of accessing records)
Relational keys
Each record in a table in the database must be unique. This means that we need to identify a
column or combination of columns (called relational keys) that provides uniqueness.
Superkey
A column, or set of columns, that uniquely identifies a record within a table. A superkey may
contain additional columns that are not necessary for unique identification.
Candidate key
A superkey that contains only the minimum number of colunms necessary for unique
identification. A candidate key for a table has two properties:
Uniqueness In each record, the values of the candidate key uniquely identifies that
record.
Irreducibility No proper subset of the candidate key has the uniqueness property.
Primary key
The candidate key that is selected to identify records uniquely within the table. Since a table
has no duplicate records, it's always possible to uniquely identify each record. This means that
a table always has a primary key. In the worst case, the entire set of columns could serve as
the primary key, but usually some smaller subset is sufficient to distinguish the records. The
candidate keys that are not selected to be the primary key are called alternate keys.
Foreign key
A colunm, or set of colunms, within one table that matches the candidate key of some table.
this helps in establishing a relationship between the two tables.
Representing relational databases
A relational database consists of one or more tables. The common convention for representing
a description of a relational database is to give the name of each table, followed by the
column names in parentheses. Normally, the primary key is underlined.
Computing science department database
Branch ( branch No , street, city, state, zipCode, mgrStaffNo)
Staff (staffNo , name, position, salary, branch No)
Relational integrity
There are two important integrity rules, which are constraints or restrictions that apply to all
instances of the database. The two principal rules for the relational model are known as entity
integrity and referential integrity.
Entity integrity
In a base table, no colunm of a primary key can be null. A base table is a named table whose
records are physically stored in the database. This is in contrast to a view which is a 'virtual
table' that does not actually exist in the database but is generated by the DBMS from the
underlying base tables whenever it's accessed.
Referential integrity
If a foreign key exists in a table, either the foreign key value must match a candidate key
value of some record in its home table or the foreign key value must be wholly null.
Relational languages
SQL (Structured Query Language)
QBE (Query-by-Example).
SQL has been standardized by the International Organization for
Standardization (ISO), making it both the formal and de facto standard language
for defining and manipulating relational databases.
QBE is an alternative, graphical-based, 'point-and-click' way of querying the
database, which is particularly suited for queries that are not too complex, and
can be expressed in terms of a few tables.
Relational calculus and relational algebra
Many high-level relational dta manipulational languages are based on either relational algebra
or relationall calculus.
Relational algebra
Refers to a collection of operations that act on relations and produce a single relation as a
result. Reasons for studying RA include:
a. RA is used as a basis for other high level data manipulation languages such SQL.
b. RA serves as a convinient basis for optimization. An optimoser is an important
component of the DBMS which decides the most appropriate strategy to adopt when
implementing a query.
c. RA is used as a measure to compare high level relational languages such as SQL and
to test if the language is relationally complete..