Skip to main content

2 Data Models

Logical data independence: Maintain views when logical structure changes

Phisical data independence: Maintain logical structure when phisical structure changes

20210506164120

ER Model

Key constraints

arrow: 可以divided(从尾到头at most one)

graph RL id1[Departments]-->id2{Manages}; subgraph 1 *did*---id1; dname---id1; budget---id1; end id2---id3[Employees]; subgraph 2 *ssn*---id3; name---id3; lot---id3; end
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

graph RL id1[Departments]==>id2{Manages}; subgraph 1 *did*---id1; dname---id1; budget---id1; end id2---id3[Employees]; subgraph 2 *ssn*---id3; name---id3; lot---id3; end
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

20210512170303

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 RR be a relation scheme

let XRX \subseteq R and YRY \subseteq R.

We say that a relation instance r(R)r(R) satisfies a functional dependency XYX \rightarrow Y if for every pair of tuples t1rt1 \in r and t2rt2 \in r, if t1[X]=t2[X]t1[X] = t2[X] then t1[Y]=t2[Y]t1[Y] = t2[Y].

ArmStrong's Axioms

Reflexivity: If XYX \supseteq Y, then XYX \rightarrow Y(trivial FD)

Augmentation: If XYX \rightarrow Y, then XZYZXZ \rightarrow YZ for any Z.

Transitivity: If XYX \rightarrow Y and YZY \rightarrow Z, then XZX \rightarrow Z

Union: If XYX \rightarrow Y and XZX \rightarrow Z, then XYZX \rightarrow YZ

Decomposition: If XYZX \rightarrow YZ, then XYX \rightarrow Y and XZX \rightarrow Z

Keys

  • A superkey is a set of attributes A1,...,AnA_1, ..., A_n s.t.

    for any other attribute B, we have A1,...,AnBA_1, ..., A_n \rightarrow B

  • A candidate key (or sometimes just key) is a minimal superkey