Data link layer -- June 20041 Data link layer Computer Networks.
Monash University 20041 Week 7 Data Modelling Relational Database Theory IMS1907 Database Systems.
-
date post
19-Dec-2015 -
Category
Documents
-
view
217 -
download
0
Transcript of Monash University 20041 Week 7 Data Modelling Relational Database Theory IMS1907 Database Systems.
Monash University 2004 2
Detailed Data Modelling
The objective of detailed data modelling is to develop data structures that- have stability, minimum redundancy, and are flexible to
allow for future change- can be used as the basis for physical file and
database design- reflect the actual data requirements of the system
Monash University 2004 3
To expand the conceptual data model we need to identify and describe – the details of the entities and relationships– attributes (data elements) of entities and relationships
An organisation-wide perspective should be adopted to ensure minimum redundancy and inconsistency and to facilitate data sharing
Detailed Data Modelling
Monash University 2004 4
Techniques- attribute collection- convert ER models to relations- normalisation- convert to data structure diagram (DSD)
Detailed Data Modelling
Monash University 2004 5
At this stage our ER models are logical– independent of implementation technology
We shall consider converting our ER models using the relational data model because– it is the most commonly used in DBMS applications– some principles of logical database design for the
relational model apply to other logical models– high level of CASE tool support
Detailed Data Modelling
Monash University 2004 6
Introduced by E.F. Codd in 1970
Represents data in the form of tables
Based on mathematical theory– solid theoretical foundation
Three components are considered– data structure– data manipulation– data integrity
Relational Data Model
Monash University 2004 7
Data structure– the relational database model represents data in the
form of tables or relations
Important concepts are- relation- primary key- composite key- foreign key
Relational Data Model
Monash University 2004 8
A relation is a named, two-dimensional table of data
Each relation consists of a set of named columns and an arbitrary number of unnamed rows
Each column corresponds to an attribute of the relation
Each row corresponds to an instance (or record) that contains values for an instance of that entity
Relations
Monash University 2004 9
A relation generally corresponds to some real world object or concept of interest to the system -similar to an entity
Emp# Name Salary Dept
1247
1982
9314
Adams
Smith
Jones
24000
27000
33000
Finance
MIS
Finance
Employee
Employee (Emp#, Name, Salary, Dept)
Relations
Monash University 2004 10
Relational tables are tables in which- each relation has a unique name- each attribute or column has a unique name- data values are atomic and single-valued- data values in columns are from the same domain- each row in the relation is unique- the sequence of columns is insignificant- the sequence of rows is insignificant
Properties of Relations
Monash University 2004 11
An attribute or group of attributes which uniquely identifies a row of a relation
A search criteria that would yield only one record
Entity integrity (relational data base theory) requires that each relation has a non-null primary key
Represented by underlining the key element– Employee (Emp#, Name, Salary, Dept)
Can be a composite key– Order-item (Order#, Item#, Qty-ordered)
Primary Key
Monash University 2004 12
Candidate keys– where several possible keys are identified, each of
which uniquely identifies the other attributes, they are known as candidate keys - choose one to be the primary key
– choose the most stable key or the key over which there is the most control
– treat the remaining candidates as non-key attributes• we can deal with them later if they give us trouble!
Primary Key
Monash University 2004 13
A foreign key is an attribute in one relation that is also a primary key in another relation in the same database– it may be a composite key– allows user to see records in one relation associated
with a record in another elation
The referential integrity constraint (relational database theory) specifies that if an attribute value exists in one relation then it must also exist in a linked relation
A foreign key must satisfy referential integrity
Foreign Key
Monash University 2004 14
In the example below, if a given Dept# exists in an Employee relation then that Dept# must exist in the Department relation
Employee (Emp#, Name, Salary, Dept#)
Department (Dept#, Dname, Budget)
foreign key
Foreign Key
Monash University 2004 15
The relational model has several constraints or rules that facilitate the maintenance of the accuracy and integrity of data in the database– domain constraints– entity integrity– referential integrity
Integrity Constraints
Monash University 2004 16
Domain constraints– all values appearing in a column of a relation must come
from the same domain of values
Domain definitions consist of – domain name– meaning– data type– size or length– allowable values or range of values
Integrity Constraints
Monash University 2004 17
Entity integrity– no primary key attribute or component of primary key
attribute can be null– ensures every relation has a primary key and all data
values for that key are valid
Null value– allowable when value is unknown or is not applicable– not a value or a zero, rather the absence of a value– inclusion in relational model is controversial – can lead
to anomalies
Integrity Constraints
Monash University 2004 18
Referential integrity– each foreign key value must match a primary key value
in another relation, or the foreign key value must be null– associations between tables are defined using foreign
keys– maintains consistency between rows in two relations– ensures every foreign key does correspond to an
existing primary key in another relation else the foreign key is null
Integrity Constraints
Monash University 2004 19
Well-Structured Relations
A well-structured relation– is robust, stable and flexible– contains a minimum amount of redundancy– allows users to insert, modify, and delete rows in a table
without errors or inconsistencies • known as “anomalies”
Monash University 2004 20
Well-Structured Relations
Three types of anomaly are possible- insertion - deletion - modification
Relations that have been normalised to third normal form (3NF) are considered to be well structured relations– although even 3NF relations can have anomalies
Monash University 2004 21
Well-Structured Relations
Insertion anomaly– cannot create a new record without supplying data
values for for two independent data elements
Deletion anomaly– cannot delete a record without losing related data in that
record that might need to exist independently
Modification anomaly– must sometimes update a data value in many records to
ensure consistency
Monash University 2004 22
A Poorly-Structured RelationCan’t add new employee till completed course
Delete emp no 150 and lose Delphi
Name changes need to be made in more than one record
Emp_ID Emp_Name Course Date_Comp
100 Jim VB .Net 2/4/03
100 Jim C++ 6/8/03
140 Jane C++ 12/10/02
110 Wendy Java 30/6/03
110 Wendy VB .Net 2/4/03
150 Robert Delphi 1/5/04