【test】

Course Outline

  • ER Model
  • Relational Model and Algebra
  • SQL
  • Functional Dependencies and Relational Database Design
  • Storage and File Systems
  • Tree and Hash Indexes
  • Query Processing and Implementation of Relational Operators
  • Query Optimization
  • Transactions
  • Concurrency Control Protocols
  • Database Recovery

Online Database

schema mode

instance instance

DBMS: Database Management System

File System (File System) The main disadvantages:

  • Redundant and inconsistent data (data redundancy and inconsistency)

  • Data access is difficult (difficulty in accessing data), data isolation (data isolation)
  • Integrity problems (integrity problem)
  • Problems atomicity (atomicity problem)
  • Concurrent access exception (concurrent-access anomaly)
  • Security issues (security problem)

Data Models Data Model:

  • Object-based logical models based on a logical model of the object:

    • Entity-Relationship Model (ER Model) entity - relationship model

      Provide a convenient way to observe the graphic data, and link constraint.

  • Record-based Logical Models based on a logical model of the record:
    • Relational Model Relational Model
  • Other:

    Network Model Network Model

    Hierarchical Model hierarchical model

    object-oriented model, objected-relational model …...

Data abstraction at three levels:

  • The physical layer (physical level)

  • Concept layer (logical layer, logical level)

  • Layer view (view level)

img

Database language

  1. Database definition language (DDL)

  2. Data Manipulation Language (DML)

It relates to information retrieval section referred to as DML query language (query language)

Use of personnel database

  1. Database administrator (DataBase Administrator, DBA): the system of centralized control of people
  2. Database users: Four types of system design different types of user interfaces for different types of users
    1. Inexperienced users (naïve user): by prior written application activation of interaction with the system, a typical user interface is a spreadsheet interface.
    2. Application Programmer (application programmer): the development of the user interface
    3. Sophisticated users (sophisticated user): not by writing a program to interact with the system, but requires a database query language expression data analysis software or other tools.
    4. Special user (specialized user): Production of special, not suitable for experienced users of traditional database application data processing framework.

DBMS structure

image-20190721110515516


ER diagram (Entity - Relationship diagram, ER Diagram)

Entity - relationship model ( the Entity-Relationship (ER) Model )

  1. Entity ( the Entity )

    • entity

    • Set entity (entity set): the same type (having the same properties / attributes) of a collection of entities.

      1. Weak entity sets (weak entity set): does not have sufficient properties constituting the entity set the primary key.
      2. Main code entity set is referred to as a strong set of entities (Entity strong SET) .
    • Property (attribute)

      • ER model classification attributes:

        1. Simple (Simple) attribute / composite (Composite) properties:

        Simple properties can not be divided into smaller parts;

        Composite properties can be divided into smaller portions (other properties). Compound properties can be hierarchical, sub-properties can be further divided.

        1. Single value (single-valued) attribute / multivalued (muti-valued) properties:

        Single-valued attribute for a particular entity is only a single value;

        Multivalued attributes have a set of values ​​corresponding to a specific entity. It indicates that the property is multi-valued braces.

        1. Derived (derived) attributes: can be derived from other related attributes or entities.
      • Code (key): sufficient to distinguish between each entity attribute set

        • Composite codes (Composite Key)

        • Code candidate (candidate key) -> master key (primary key)

  2. Contact ( Relationship)

    • contact

      • Recursive Relationship
    • Constraints (Constraints)

      • Mapping Type:
        1. One (one-to-one)
        2. To-many (one-to-many)
        3. Many-to (many-to-one)
        4. To-many (many-to-many)

      image-20190721113706782

      • Participation constraint
        1. If the set E of entities each entity involved in the at least one contact link set R, the set of entities participating in a link set R E is referred to in all ( Total)
        2. If only part of the entity set E Contact entities involved in the set R, the set of entities to participate in E is called a link set R portion (partial) .
    • Contact Set

      • Two yuan (binary) set Contact: Contact involve two sets entity set. Most of the contact set dbms are binary.
      • Non-binary link set

    EG. entity set three instructor, student and project proj_guide by contacting associated set.

    3. Class Hierarchy

    img

    img


    Relational model Relational Model

    Basic terms

    FIG ER into relational model

    step:

    Step 1 (Strong Entity Set)

    Step 2 (Weak Entity Set)

    Step 3 (1-to-1 Relationship)

    Step 4 (1-to-many Relationship)

    Step 5 (Many-to-many Relationship)

    Step 6 (Non-binary Relationship)


关系代数 Relational Algebra

  1. 基本运算

    1. 选择(select)运算:选出满足给定谓词的元组。

      用小写sigma(σ)表示,下标为谓词,括号中为参数关系。

    2. 投影(project)运算:返回作为参数的关系,但把某些属性排除在外,所有重复行均被去除。

      用大写pi(Π)表示,下标为在结果中出现的属性,括号中为参数关系。

    3. 并(union)运算

    4. 集合差(set-difference)运算

    5. 笛卡尔积(Cartesian-product)运算:将任意两个关系的信息组合在一起,结果中包含所有可能的元组对。

    6. 更名(rename)运算:给关系代数表达式的结果赋上名字以供引用。

      用小写rho(ρ)表示。

  2. 附加运算

    1. 集合交(intersection)运算 (∩)
    2. 连接(join)运算 (⋈)
    3. 除法(division)运算(/)

SQL

SQL:结构化查询语言

  1. 数据定义语言(Data-Definition Language, DDL):

    SQL DDL提供定义定义关系模式、删除关系以及修改关系模式的命令。

    SQL数据定义

    1. 固有类型

      ·char(n):固定长度(用户指定n)的字符串,等价全称character。​
      
      存入字符串长度不够时会追加空格使其达到固定长度;
      
      比较长度不同的char类型值时会自动在短值后追加空格使长度一致。
      
      ·varchar(n):可变长度(用户指定最大长度n)的字符串,等价全称character varying。
      
      Varchar类型不会增加空格。
      
      ·int:整数类型,等价全称integer。
      
      ·smallint:小整数类型。
      
      ·numeric(p, d):精度由用户指定(加上一个符号位有p位数字,其中d位数字在小数点右边)的定点数。
      
      ·real, double precision:浮点数与双精度浮点数。
      
      ·float(n):精度至少为n位的浮点数。
      
      SQL也提供nvarchar类型存放使用Unicode表示的多语言数据。

      每种类型都可能包含空值,表示一个缺失的值,应尽量避免加入空值。

    2. 基本模式定义

      • drop table:删除关于被去掉关系的所有信息

        drop table r; 
        --删除r的所有元组以及r的模式,除非用create table重建r否则没有元组可以插入r中
      • alter table:为已有关系增加属性(关系中在所有元组在新属性上的取值将被设为null)

        alter table r add A D; --为关系r添加域为D的属性A
        alter table r drop A; --为关系r中去掉属性A,很多数据库系统并不支持
      完整性约束(ICs):

      破坏完整性约束的任何数据库更新将会被标记错误并禁止。

      扩展运算:

      数据库的修改

      • delete 删除

        delete from r
        where P;
        /*P代表一个谓词,r代表一个关系。Delete语句首先从r中找出所有时P(t)为真的元组t,然后把它们从r中删除。*/
      • insert 插入元组
      • update 更新:不改变整个元组的情况下改变其部分属性的值。

      视图(view)

      不是逻辑模型的一部分,但作为虚关系对用户可见的关系。

      定义视图:

      create view v as <query expression>;
      --v表示视图名,<query expression>可以是任何合法的查询表达式。

      断言(assertion)

      create assertion <assertion-name> check <predicate>;

      触发器(trigger)

  2. 数据操纵语言(Data-Manipulation Language, DML):

    SQL DML包括查询语言,以及在数据库中插入元组、删除元组和修改元组的命令。

    • SQL查询的基本结构(Basic SQL Query)

    • 算术运算(Arithmetic Operation)

    • 更名运算(Rename Operation)

      as子句 old-name as new-name

      既可出现在select子句,也可出现在from子句中。

      select T.name, S.course_id
      from instructor as T, teaches as S --重命名关系
      where T.ID = S.ID;  

      重命名关系适用于需要比较同一关系中元组的情况

    • 字符串运算(String Operation)

      like 操作符模式匹配:(大小写敏感)

      % 匹配任意子串

      _ 匹配任意一个字符

    • 排列元组显示次序(Ordering the Display of Tuples)

      order by子句 让查询结果中元组按特定属性排序(默认升序)

      升序:asc

      降序:desc

      //按salary降序列出整个instructor关系,如果有几位教师的工资相同,就按姓名升序排列
      select *
      from instructor
      order by salary desc, name asc;
    • 聚集运算(Aggregate Operator)

      In a set (or multiple sets set) value as input, returns a single value

    • Set operations (Set Operation)
      • union and
      • intersect pay
      • except 差
    • Division (Division)

    • Group (Group By)

      group by子句For the construction of the packet. All attributes specified value tuples will be the same points in a group.

    • Null (NULL value)
    • Sequence (Sequence)

Guess you like

Origin www.cnblogs.com/Ryan0v0/p/11221154.html