数据库原理笔记

数据库原理

我们为什么不用文件存储数据,

拿C语言IO操作来讲,能实现的只有Create Open Read Write Lseak,而且,如果用文件存储的话,我们要根据不同的存储设计不同的结构,相反DBMS只管和他要东西就行

Files vs. Databases

■ Application must stage large datasets between main memory and secondary storage (e.g.,buffering, page-oriented access, 32-bit addressing,etc.)
■ Special code for different queries
■ Must protect data from inconsistency due to
multiple concurrent users
■ Crash recovery
■ Security and access control

Why Use a DBMS?

■Data independence and efficient access.
■Reduced application development time.
■Data integrity and security.
■Uniform data administration.
■Concurrent access, recovery from crashes.

Why Study Databases ?

■Shift from computation to information
➢at the "low end": scramble to webspace (a mess!)
➢at the "high end": scientific applications
■Datasets increasing in diversity a
and volume.
➢Digital libraries, interactive video, Human Genomeproject, EOS project
➢... need for DBMS exploding
■DBMS encompasses most of Computer Science
➢OS, languages, theory, AI, multimedia, logic

**Data, Data Model and Data Schema **

■Data are symbols for describing the things of real world. They are existing form of information.
■A data model is a collection of concepts and definitions for describing data.
■A schemna is a description of a particular collection of data,using a given data model.
■The relational model of data is the most widely used model today.
➢Main concept: relation, basically a table with rows and columns.
➢Every relation has a schema, which describes the columns, or fields.。

Levels of Abstraction

■Many vievs, single conceptual (logical) schema and phuysical schema.
➢Views describe how users the data.
➢Conceptual schema defineslogical structure
➢Physical schema describes the files and indexes used.

Example: University Database

■Conceptual schema:
➢Students(sid: string, name: string, login: string,age: integer, gpa:real)
➢Courses(cid: string, cnane:string, credits:integer)
➢Enrolled(sid:string, cid:string, grade:integer)
■Physical schema:
➢Relations stored as unordered files.
➢Index on first column of Students.
■External Schema (View):
➢Course_ info(cid:string,enrollment:integer)

应用程序都是基于外模式开发的

Data Independence

■Applications insulated from how data is structured and stored.
■Logical data independence: Protection from changes in logical structure of data.
■Physical data independence: Protection from changes in physical structure of data.

  • One of the most important benefits of using a DBMS!

三级模式和两级映射

​ 美国家标准协会(American National Standard Institute,ANSI)的数据库管理系统研究小组于1978年提出了标准化的建议,将数据库结构分为3级:面向用户或应用程序员的用户级、面向建立和维护数据库人员的概念级、面向系统程序员的物理级。用户级对应外模式,概念级对应模式,物理级对应内模式,使不同级别的用户对数据库形成不同的视图。所谓视图,就是指观察、认识和理解数据的范围、角度和方法,是数据库在用户“眼中”的反映,很显然,不同层次(级别)用户所“看到”的数据库是不相同的。

1.模式

模式又称概念模式或逻辑模式,对应于概念级。它是由数据库设计者综合所有用户的数据,按照统一的观点构造的全局逻辑结构,是对数据库中全部数据的逻辑结构和特征的总体描述,是所有用户的公共数据视图(全局视图)。它是由数据库管理系统提供的数据模式描述语言(Data Description Language,DDL)来描述、定义的,体现、反映了数据库系统的整体观。

理解:

① 一个数据库只有一个模式;

② 是数据库数据在逻辑级上的视图;

③ 数据库模式以某一种数据模型为基础;

④ 定义模式时不仅要定义数据的逻辑结构(如数据记录由哪些数据项构成,数据项的名字、类型、取值范围等),而且要定义与数据有关的安全性、完整性要求,定义这些数据之间的联系。

2. 外模式

  外模式又称子模式,对应于用户级。它是某个或某几个用户所看到的数据库的数据视图,是与某一应用有关的数据的逻辑表示。外模式是从模式导出的一个子集,包含模式中允许特定用户使用的那部分数据。用户可以通过外模式描述语言来描述、定义对应于用户的数据记录(外模式),也可以利用数据操纵语言(Data Manipulation Language,DML)对这些数据记录进行处理。外模式反映了数据库的用户观(视图、查出数据的表)。

理解:

① 一个数据库可以有多个外模式;

② 外模式就是用户视图;

③ 外模式是保证数据安全性的一个有力措施。

3. 内模式

   内模式又称存储模式,对应于物理级,它是数据库中全体数据的内部表示或底层描述,它描述了数据在存储介质上的存储方式及物理结构(顺序存储、按照B树结构存储还是按hash方法存储),对应着实际存储在外存储介质上的数据库。内模式由内模式描述语言来描述、定义,它是数据库的存储观。

理解:

① 一个数据库只有一个内模式;

② 一个表可能由多个文件组成,如:数据文件、索引文件。

   在一个数据库系统中,只有唯一的数据库,因而作为定义、描述数据库存储结构的内模式和定义、描述数据库逻辑结构的模式,也是惟一的,但建立在数据库系统之上的应用则是非常广泛、多样的,所以对应的外模式不是惟一的,也不可能是惟一的。

4.两级映射

从上图中可以看到用户应用视图根据外模式进行数据操作,通过外模式一模式映射,定义和建立某个外模式与模式间的对应关系,将外模式与模式联系起来,当模式发生改变时,只要改变其映射,就可以使外模式保持不变,对应的应用程序也可保持不变;

      另一方面,通过模式一内模式映射,定义建立数据的逻辑结构(模式)与存储结构(内模式)间的对应关系,当数据的存储结构发生变化时,只需改变模式一内模式映射,就能保持模式不变,因此应用程序也可以保持不变。

     通过外模式-模式映射和模式-内模式映射这两个映射保证了数据库系统中的数据具有较高的逻辑独立性和物理独立性。

当数据库模式发生变化时,例如关系数据库系统中增加新的关系、改变关系的属性数据类型等,可以调整外模式/模式间的映像关系,保证面向用户的各个外模式不变。应用程序是依据数据的外模式编写的,从而应用程序不必修改,保证了数据与应用程序的逻辑独立性,简称数据的逻辑独立性。
当数据库中数据物理存储结构改变时,即内模式发生变化,例如定义和选用了另一种存储结构,可以调整模式/内模式映像关系,保持数据库模式不变,从而使数据库系统的外模式和各个应用程序不必随之改变。这样就保证了数据库中数据与应用程序间的物理独立性,简称数据的物理独立性。

数据库分类

The History of Database Technology and its Classification

(1) According to the development of data model

No management(before 1960 ENIAC ): Scientific computing
File system: Simple data management
■Demand of data management growing continuously, DBMS emerged.

➢1964, the first DBMS (American): IDS, network
➢1969, the first commercial DBMS of IBM, hierarchical
➢1970, E.F.Codd(IBM) bring forward relational data model
➢Other data model: Object Oriented, deductive, ER,....

(2) According to the development of DBMS architectures
■Centralized database systems Parallel database systems
■Distributed database systems (and Federated database systems)
■ Mobile database systems

(3) According to the development of architectures of application systems based on databases
■Centralized structure : Host + Terminal
■Distributed structure
■Client/Server structure
■Three tier/multi-tier structure
■Mobile computing
■Grid computing/ Cloud computing

(4) According to the expanding of application fields
■OLTP
■Engineering Database
■Deductive Database
■Multimedia Database
■Temporal Database
■Spatial Database
■Data Warehouse, OLAP, Data Mining
■Knowledge Management
■。。。

时态数据库,例如说,张三九月份工资1000块,这个月涨到1500,平常的数据库我们用Update更新之后,如果我们想知道张三九月份的工资是多少,我们是无法查询的,因为后来的Update已经覆盖了信息,所以考虑一下时态数据库。

用户请求数据库的模式

1. C/S

2. B/S

原文地址:https://www.cnblogs.com/qzdd/p/12391648.html