数据库
数据库语言
- SQL 语言:
- 数据定义语言(DDL)define
- 数据操纵语言(DML)management
- 数据控制语言(DCL)control
Drawbacks of DBS
- data redundancy and inconsistency
- duplication of info in differ files
- cost high
- data isolation
- multiple files and formats
- diffi in accessing data
- data updates differently
- access by many users at same time
- security
View of data
- abstraction view
- physical level: 是数据库用户能够看见和使用的逻辑结构和特征的描述,与某一应用相关的数据的逻辑表示
- logical level : 是数据库中所有数据的逻辑结构和特征的描述
- view level
Independence
- phy data independence : application dont depend on phy schema
- logical data independence: 保护用户不受数据逻辑结构变化的影响
Basic structure
tuple
: rowattributes
: column namedegree/arity
: number of attributescardinality
(基数): number of tulpesrelation schema
:
Keys
super key
:能唯一标识row
的attribute/attributes
,可能包含extraneous attributes
,不唯一candidate key
: 能唯一标识row
的attribute/attributes
,不唯一。是mininal super key
。If any propersubset
of asuper key
is asuper key
then that key cannot be acandidate key
prime attribute
:至少属于一个candidate key
的 `attributeForeign keys
: 外键
模式和视图
- 模式(数据的结构):对数据库中数据进行的一种结构性的描述
- 视图(展现的数据):某一表现形式下表现出来的数据库中的数据
关系模型
关系模型的完整性
- 实体完整性
- 主码的属性值不能为空值
- 参照完整性 (关系间连接的正确性))
- 如果关系 R 1 的外码 Fk 与关系 R 2 的主码 Pk 相对应,则 R 1 中的每一个元组的 Fk 值等于 R 2 中某个元组的 Pk 值或者为空值
- 用户自定义完整性
关系代数
- 基本操作:
- 差(difference)
- 笛卡尔积(product):
- R 和 S 中的元组进行所有可能的拼接; R × S=R × S;
- 元组数目=R * S ;
- 属性数目=R+S
- 选择(select)
- r 是关系/表名
- r 是关系/表名
- 投影(projection):
- 从若干列中选出某列
- rename operation:
- 扩展操作:
- 连接 (join)
- 等值连接
- 自然连接
- 特殊的等值连接:相同的属性组去掉
- 特殊的等值连接:相同的属性组去掉
- left join/right join/full outer join
- 除(division)(派生运算符)
- R ÷ S :R divided by S
- 一般用于求解”查询····全部的/所有的”的问题
- Aggregate/sum
- Take collection of values, returns a single value
- Take collection of values, returns a single value
- 连接 (join)