Data Models
Logical data independence: Maintain views when logical structure changes
Phisical data independence: Maintain logical structure when phisical structure changes
ER Model
Key constraints
arrow: 可以divided(从尾到头at most one)
create table manages(
ssn char(11),
did integer,
primary key (did),
foreign key (ssn) references Employees,
foreign key (did) references Departments
)
Participation constraints
粗线: Total participation(从尾到头at least one)
故以下从尾到头exactly one
create table manages(
did integer,
dname char(20),
budget real,
ssn char(11) not null,
primary key(did),
foreign key (ssn) references Employees on delete no action
)
Weak Entity Set
An entity set that does not have a primary key
create table Dep_Policy(
pname char(20),
age integer,
cost real,
ssn char(11) not null,
primary key (pname,ssn),
foreign key (ssn) references employees on delete cascade
)
Functional Dependencies
Definition
Let R R R be a relation scheme
let X ⊆ R X \subseteq R X⊆R and Y ⊆ R Y \subseteq R Y⊆R.
We say that a relation instance
r
(
R
)
r(R)
r(R) satisfies a functional dependency
X
→
Y
X \rightarrow Y
X→Y if
for every pair of tuples
t
1
∈
r
t1 \in r
t1∈r and
t
2
∈
r
t2 \in r
t2∈r, if
t
1
[
X
]
=
t
2
[
X
]
t1[X] = t2[X]
t1[X]=t2[X] then
t
1
[
Y
]
=
t
2
[
Y
]
t1[Y] = t2[Y]
t1[Y]=t2[Y].
ArmStrong’s Axioms
Reflexivity: If X ⊆ Y X \subseteq Y X⊆Y, then X → Y X \rightarrow Y X→Y(trivial FD)
Augmentation: If X → Y X \rightarrow Y X→Y, then X Z → Y Z XZ \rightarrow YZ XZ→YZ for any Z.
Transitivity: If X → Y X \rightarrow Y X→Y and Y → Z Y \rightarrow Z Y→Z, then X → Z X \rightarrow Z X→Z
Keys
-
A superkey is a set of attributes A 1 , . . . , A n A_1, ..., A_n A1,...,An s.t.
for any other attribute B, we have A 1 , . . . , A n → B A_1, ..., A_n \rightarrow B A1,...,An→B
-
A candidate key (or sometimes just key) is a
minimal superkey