Date post: | 01-Jun-2018 |
Category: |
Documents |
Upload: | dayton-good-kush-allen |
View: | 217 times |
Download: | 0 times |
of 22
8/9/2019 lec3a_DataModels
1/22
1
Data Models
How to structure data
8/9/2019 lec3a_DataModels
2/22
2
What is a Data Model?
Having formed a model of the enterprise, we now need torepresent the data.
The data model tells us the structure of the database.
Historicall, three data models!
Hierarchical data model
"etwor# data model
$elational data model
8/9/2019 lec3a_DataModels
3/22
%
Hierarchical and "etwor# Data Models
Hierarchical and networ# data models have beensuperseded b the relational data model.
$easons!
&ac# of e'pressive power
(.g. one cannot e'press man)to)manrelationships in the hierarchical model
More closel tied to the underling implementation.
Hence, less data independence.
$elational data model has a clean mathematical basis.
8/9/2019 lec3a_DataModels
4/22
*
The $elational Model
Due to +odd. (verthing is represented as a relation in the
mathematical sense. lso called tables.
database therefore is a collection of tables, each of
which has a uni-ue name, and each of which is describedb a schema.
n addition, +odd defined a data manipulation language.
8/9/2019 lec3a_DataModels
5/22
/
('ample of 0chemas in the $elational Model
('ample of a representation of entit sets!
Student(sid,name,addr)
Course(cid,title,eid)
Empl(eid, ename, deptid)
Dept(deptID, dname, loc)
rimar #es are underlined.
$ecall that a primar #e is one that uni-uel identifies an
entit.
n entit is a row in a table.
8/9/2019 lec3a_DataModels
6/22
More ('ample 0chemas
$elationship sets between entit sets are alsorepresented in tables.
('ample of a table corresponding to a relationship!
Enrol(sid, cid, grade)
gain, a relationship is represented b a row 3or a tuple4in a table.
8/9/2019 lec3a_DataModels
7/22
5
$elational Databases!
6asic +oncepts
Attribute:
column in a table
Domain
The set of values from which the values of an attribute
are drawn. Null value
special value, meaning 7not #nown8 or 7not
applicable8.
Relation schema set of attribute names
8/9/2019 lec3a_DataModels
8/22
9
$elational Databases! 6asic +oncepts
Tuple
set of values, one for each attribute in the relation
schema over which the tuple is defined, i.e. a mapping
from attributes to the appropriate domains
Relation instance set of tuples over the schema of the relation
8/9/2019 lec3a_DataModels
9/22
:
$elational Databases!
6asic +oncepts
Relational Database
set of relations, each with a uni-ue name
Normalized Relation
relation in which ever value is atomic 3non)
decomposable4. Hence, ever attribute in ever tuplehas a single value.
8/9/2019 lec3a_DataModels
10/22
1;
8/9/2019 lec3a_DataModels
11/22
11
Foreign Key
n attribute 3or set of attributes4 in table $1 which also
occurs as the primar #e of relation $2.
$2 is called the referenced relation.
=oreign #es are also called connection #es orreference attributes.
8/9/2019 lec3a_DataModels
12/22
12
ntegrit $ules! (ntit +onstraint
ntity constraint ll attributes in a primar #e must be non)null.
Motivation! f the primar #e uni-uel identifies an
entit in an entit set, then we must ensure that we
have all the relevant information
8/9/2019 lec3a_DataModels
13/22
1%
ntegrit $ules!
$eferential ntegrit
$eferential integrit database cannot contain a tuple with a value for a
foreign #e that does not match a primar #e value in
the referenced relation.
>r, a foreign #e must refer to a tuple that e'ists. Motivation! f referential integrit were violated, we
could have relationships between entities that we do
not have an information about.
8/9/2019 lec3a_DataModels
14/22
+onverting ($ Diagrams to $elational 0chemas
3tables4
database which conforms to an ()$ diagram can berepresented b a collection of relations 3tables4.
=or each entit set and relationship set there is a uni-ue
relation that is assigned the name of the corresponding
entit set or relationship set. (ach schema has a number of columns 3generall
corresponding to attributes4, which have uni-ue names.
1*
8/9/2019 lec3a_DataModels
15/22
$epresenting (ntit 0ets as $elations 3tables4
strong entit set reduces to a relation with the attributesof the entit.
+ourse3cid, ctitle4
wea# entit set becomes a table that includes the
primar #e of the strong entit set. ('ample!
0ection3cid, secno, -uota4
1/
8/9/2019 lec3a_DataModels
16/22
$epresenting $elationship 0ets as
$elations 3tables4
man)to)man relationship set is represented as arelation with attributes for the primar #es of the two
participating entit sets, and an attributes of the
relationship set.
('ample! (nrolls3sid, cid, grade4
1
8/9/2019 lec3a_DataModels
17/22
Total articipation
The participation of an entit set in a relationship set istotal if each entit in the set occurs in at least one
relationship in that relationship set
15
8/9/2019 lec3a_DataModels
18/22
$epresenting $elationship 0ets as
$elations 3tables4
Man)to)one and one)to)man relationship sets thatare total on the man)side can be represented b
adding an e'tra attribute to the 7man8 side,
containing the primar #e of the 7one8 side.
('ample! +ourse3cid,ctitle,lid4
f participation is not total on the 7man8 side,
replacing the relationship table b an e'tra attribute
in the relation corresponding to the 7man8 side couldresult in null values.
19
8/9/2019 lec3a_DataModels
19/22
$epresenting $elationship 0ets as
$elations 3tables4
=or one)to)one relationship sets an e'tra attribute can beadded to either of the tables corresponding to the two
entit sets.
The relation corresponding to a relationship set lin#ing a
wea# entit set to its identifing strong entit set isredundant.
('ample! The section entit alread contains the
attributes that would appear in the relation 3i.e. cid and
secno4.
1:
8/9/2019 lec3a_DataModels
20/22
$epresenting 0pecialiation
Method 1! +reate a relation for the higher)level entit.
+reate a relation for each lower)level entit set,include primar #e of higher)level entit set and localattributes.
('ample! 0tudent3sid,sname4 @raduate3sid,supervisor4 Andergraduate3sid,credits4
Drawbac#! getting information about a student mare-uire accessing two relations 3i.e. both the low)leveland the high)level relation4.
2;
8/9/2019 lec3a_DataModels
21/22
$epresenting 0pecialiation
Method 2! =orm a relation for each entit set with all local and
inherited attributes. ('ample!
0tudent3sid,sname4
Andergraduate3sid,sname,credits4 @raduate3sid,sname,supervisor4 f specialiation is total, the schema for the generalied
entit set 3student4 is not re-uired to store information. +an be defined as a 7view8 relation containing union of
specialiation relations Drawbac#! some amount of redundanc ma be
introduced in the design.
21
8/9/2019 lec3a_DataModels
22/22
$epresenting ggregation
22
Customer LoanBorrows
Employee
Loan-Manager
B Loan-Manager (employee_id, customer_id, loan_id)B Relation Borrows is redundant
What is the primary ey in this relation!