西工大数据库系统期末复习

数据库

一、数据库系统

1.数据库:

A shared collection of logically related data, and a description of this data, designed to meet the information needs of an organization.

逻辑相关的数据的共享集合,以及对数据的描述,被设计来满足组织的数据需求。

2.数据库管理系统:

    A software system that enables users to define, create, maintain, and control access to the database.

    允许用户定义、创建、维护数据库和控制数据库的访问的软件系统。

3.数据库系统

    A database system is developed to support the operations of a specific organization or a specific set of applications.

    用来支持特定组织或一组特定应用程序的运作。包含:特定应用的数据库、维护数据库的数据库管理系统、使用数据库的应用程序。

4.数据库作为数据管理系统的特点:

    数据抽象:数据统一结构化,结构信息独立于数据

    高可靠:支持完整性约束,保证数据一致性

    高效:物理贮存优化,控制冗余查询优化,并发访问控制

二、关系模型

关系模型特征:数据结构、完整性约束

1.数据结构:

    The relational model is based on the mathematical concept of a relation, which is physically represented as a table.

关系模型基于关系的数学概念,该概念在物理上表示为表。

The relational data structure are principally based on set theory and predicate logic from mathematics.

关系数据结构主要基于数学中的集合论和谓词逻辑。

2.关系:

    A relation is a table with columns and rows.

    关系是包含列和行的表。

    Mathematical definition -- Any subset of n-tuples from the Cartesian product of n sets is a relation on the n sets.

    n个集合的笛卡尔积的任何n元组子集都是n个集合上的关系。

3.关系中的码或键:

    超码:

       An attribute, or set of attributes, that uniquely identifies a tuple within a relation.

       一个或多个属性的集合,能够唯一标识关系中的每一个元组

    候选码:

       A super key such that no proper subset is a super key within a relation.

       关系中唯一标识每个元组的最小属性集合

    主码:

       The candidate key that is selected to identify tuples uniquely within a relation.

       从候选码中选择的一个作为主要的唯一标识符

    辅码:

       A candidate key that is not selected to be the primary key.

       未被选择作为主码的候选码。

    外码:

       An attribute, or set of attributes, within one relation that matches the candidate key of some (possibly the same) relation.

       一个关系中的属性或多个属性,引用了另一个表中的候选键以建立两个表之间的关系。

4.关系模式(Relation Schema)的表示

Give the name of the relation followed by the attribute names in parentheses. Usually underline the primary key

Student (sNo, sName, sSex, sAge, sDept)

Course (cNo, cName, cPNo, cCredit)

SC (sNo, cNo, score)

5.空值NULL的含义

Null represents a value for an attribute that is currently unknown or is not applicable for this tuple.

Null can cause implementation problems because the relational model is

based on predicate calculus, which is a two-valued or Boolean logic.

The incorporation of nulls in the relational model is a contentious issue.

缺少值或未知值

6.完整性约束

    实体完整性:

In a base relation, no attribute of a primary key can be null.

       主键不能为空

    参照完整性:

If a foreign key exists in a relation, either the foreign value must match a candidate key value of some tuple in its home relation or the foreign key value must be wholly null.

       在建立表与表之间的关联时,引用表中的外键值必须存在于主表的候选键中。

    用户定义完整性:

Additional rules specified by the users or database administrators of a database.

       由数据库的用户或管理员指定的其他规则。

三、数据库设计概述

    The database is a fundamental component of an information system.

    数据库是信息系统的基本组成部分。

    The lifecycle of an organization’s information system is inherently linked to the lifecycle of the database system that supports it.

    一个组织的信息系统的生命周期与支持它的数据库系统的生命周期有着内在的联系。

四、并发控制

五、事务

1.事务

       A transaction is a sequence of database statements that needs to execute atomically.

       一组数据库操作组成的逻辑单位

    包含:

    DML:数据操作语言(INSERT、UPDATE、DELET、SELECT)

    DDL:数据定义语言(CREATE、ALTER、DROP)

    DCL:数据控制语言(GRANT、REVOKE、DENY)

2.ACID特性:

1)原子性(Atomicity):事务被视为一个不可分割的单元,要么全部操作成功提交,要么全部操作失败回滚

2)一致性(Consistency):事务的执行保持数据库的一致性状态,事务开始前和结束后,数据库必须满足所有的完整性约束。

3)隔离性(Isolation):每个事务的执行被视为相互隔离的,事务之间的操作互不干扰。

4)持久性(Durability):一旦事务成功提交,其对数据库的修改永久保存。

六、关系代数

并:R∪S={t|t∈R∨t∈S}

差:R-S={t|t∈R∧tS}

交:R∩S={t|t∈R∧t∈S}

笛卡尔积:R´S

选择:σF(R)={t|t∈R∧F(t)=‘true’}

投影:ΠA(R) = { t[A] | t∈R }

从关系(表)中选择指定的列(属性),并生成一个新的关系(表),其中只包含选定的列

自然连接:

外连接:

七、SQL

1.Sulting Results(ORDER BY)

       SELECT 列名1,列名2

       FROM 表名

       ORDER BY 列名 ASC(DESC);

2.Aggregate Functions

COUNT(column)计算指定列非空值的数量;COUNT(*)计算整个表中的行数(包括NULL)

       SELECT COUNT(column)

       FROM table;

       SUM(column)计算某一列的数值总和

       AVG(column)计算某一列数值的平均值

       MAX(column)获取指定列的最大值

3.Grouping Results

    GROUP BY用于按照一个或多个列对结果进行分组,结合聚合函数使用

    SELECT 列名1,COUNT(列名2)

    FROM 表名

    GROUP BY 列名1;

4.Restricting Groupings

    Having用于在GROUP BY后对分组结果进行过滤

    SELECT 列名1,COUNT(列名2)

    FROM 表名

    GROUP BY 列名1

    Having 条件;

5.self-join

       SELECT c2.cName

FROM Course c1, Course c2

WHERE c1.cPNo=c2.cNo

AND c1.cName=‘数据库’;

6. outer join

       SELECT s.*, sc.*

FROM Student s, SC sc

WHERE s.sNo = sc.sNo;

SELECT s.*, sc.*

FROM Student s LEFT [OUTER] JOIN SC sc ON s.sNo = sc.sNo;

7. multi-table join

SELECT s.sName, c.cName, sc.score

FROM Student s, Course c, SC sc

WHERE s.sNo = sc.sNo and c.cNo=sc.cNo;

八、索引

    An index is a structure that provides accelerated access to the rows of a table based on the values of one or more columns.

    索引存储了表中一个或多个列的值和对应的物理位置,是一种数据结构,用于提高数据的检索速度和查询性能

    CREAT INDEX index_name ON table_name (column1,column2,…);

九、视图

The dynamic result of one or more relational operations on the base relations to produce another relation.

A view is a virtual relation that does not necessarily exist in the in the database but can be produced upon request by a particular user, at the time of request.

The DBMS stores the definition of the view but not the data in the database.

    视图是基于查询语句定义的虚拟表。视图并不实际存储数据,二十根据预定义的查询逻辑动态生成的结果集。通过视图,可以从一个或多个数据库表中提取和组织数据,形成一个逻辑上的数据视图。

CREATE VIEW view_1

AS SELECT s.sName, c.cName, sc.score

FROM Student s, Course c, sc

WHERE s.sNo=sc.sNo and c.cNo=sc.cNo

and c.cName='离散数学';

WITH CHECK OPTION确保对视图的更新操作仅限于符合视图定义条件的数据

       CREATE VIEW IS_Student

AS SELECT *

FROM student

WHERE dNo IN(SELECT dNo

FROM department

WHERE dName='信息学院')

WITH CHECK OPTION

优点:数据独立性、即时性、安全性、降低复杂度、便利、用户化、数据完整性

缺点:更新限制、结构限制

十、访问控制

       授权

GRANT 权限列表

       ON 对象类型 对象名称

       TO用户或用户组

       [WITH GRANT OPTION]

      

       撤销权限

       REVOKE 权限列表

       ON 对象类型 对象名称

       TO用户或用户组

十一:存储过程和触发器

存储过程:是一组为了完成特定功能的SQL语句集,它存储在数据库中,一次编译后永久有效,用户可以通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行或者调用它。

触发器:数据库管理系统发生特定变化时自动执行的一系列操作

       EVENT事件

       CONDITION条件

       ACTION操作

十二:SQL应用

1.SQL限制

       Complex computational processing of the data.

数据的复杂计算处理

       Specialized user interfaces.

专用的用户界面

       Access to more than one database at a time.

一次访问多个数据库

嵌入式-将SQL直接嵌入到通用程序设计语言,各司其职。

应用编程接口(API)-通过库函数(接口)调用,实现与数据库交互。

设计新语言(混合)-支持SQL和通用程序设计语言特性。

2.阻抗失配

数据库模型与程序设计语言模型之间存在的差异而导致的不匹配问题。

3.通过JDBC访问数据库

    Load the JDBC driver

Connect to the data source

Execute SQL statements

4.模型、视图、控制器体系结构(MVC)

The Model View Controller (MVC) architecture describes a way to organize and separate the tasks of an application into three distinct parts: Model, View, and Controller.

The View manages the output of a user interface.

The Controller processes the user's input.

The Model represents the data and logic of the subset of the external world used in the progra

十三、概念设计

生存周期

十四、逻辑设计

ER图

十五、关系模式规范化

1NF:确保每个属性只包含一个值,不可再分

2NF:不存在非主属性对主属性的部份依赖

3NF:不存在非主属性对非主属性的传递依赖

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Xifan_Lee

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值