cs186 lecture2 --Data Models

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)

1
2
Employees
*ssn*
name
lot
Departments
*did*
dname
budget
Manages
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

1
2
Employees
*ssn*
name
lot
Departments
*did*
dname
budget
Manages
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 R R R be a relation scheme

let X ⊆ R X \subseteq R XR and Y ⊆ R Y \subseteq R YR.

We say that a relation instance r ( R ) r(R) r(R) satisfies a functional dependency X → Y X \rightarrow Y XY if
for every pair of tuples t 1 ∈ r t1 \in r t1r and t 2 ∈ r t2 \in r t2r, 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 XY, then X → Y X \rightarrow Y XY(trivial FD)

Augmentation: If X → Y X \rightarrow Y XY, then X Z → Y Z XZ \rightarrow YZ XZYZ for any Z.

Transitivity: If X → Y X \rightarrow Y XY and Y → Z Y \rightarrow Z YZ, then X → Z X \rightarrow Z XZ

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,...,AnB

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值